问题描述
新:
我必须重新定义问题的描述。我使用提取的数据的不同变体检查了各个查询本身的统计信息。通常,单个查询似乎还可以(它们不会拖延自己并且可以正常工作)。在应用程序运行时会发生此问题。该应用程序是一个互联网游戏。 在一个游戏过程中,新记录(具有游戏的当前状态)将不断写入数据库。这时有很多插入物。 用户可能希望随时(在进行此类插入时)查看游戏的历史记录。 此时,当写入服务将新记录添加到数据库中时,读取服务将读取数据。与书写相比,这种阅读非常少见,发生比例为1:100(但将来这种阅读会更频繁)。 此类阅读被延迟。 对于这个特殊的问题,我考虑复制MASTER-SLAVE(writeonly-readOnly)
其他信息评论员询问:
• Cloud service: gcp
• Service limit: limits:
memory: 1500Mi
cpu: 500m
• Postgres version: 10
• System log @R_570_4045@ion as to resource usage: I can't get it yet
• Postgres logs @R_570_4045@ion from slow periods: I can't get it yet
• Is cloud service doing automatic database,OS backup: no
• if only 1% of requests are reads,what are the other requests doing: insert new records
OLD:
最近我问了我的数据库问题:(“大家好,我有基于Postgresql云的数据库,每天发出150万个请求,其中只有1%是读取请求。 问题是频繁的随机读取延迟。服务ugh-read通常在0-6秒内读取数据。有时读取时间会增加到40甚至100秒以上。 罕见的跳跃(如10-20秒)是可以接受的,但是我绝对需要摆脱40秒以上的跳跃,尤其是随着时间的推移,读数的数量会逐渐增加。 我考虑进行异步MASTER-SLAVE复制,主服务器负责写入,而从服务器负责读取。我不确定这是否是个好主意?”)。有人指示我更具体地提出问题。我发现有延迟的方法。我想重复这些问题,显然在下面添加了一些细节:
我的数据库资源:
resources:
requests:
memory: 1500Mi
cpu: 200m
limits:
memory: 1500Mi
cpu: 500m
服务方法:
public Page<UserGameHistory> getGameHistory(String userId,String gameCode,String operatorCode,int page,int limit) {
Validator.from(InputParamsException::new)
.notEmpty(userId,"User id is not present")
.notEmpty(operatorCode,"Operator code is not present")
.notEmpty(gameCode,"Game code is not present");
PageRequest request = PageRequest.of(page,limit,USER_HISTORY_SORT);
userId = userIdConverter.fromUnkNownToPROPER_NAME(userId,operatorCode);
return historyRepository
.findByUserIdAndGameCodeAndOperatorCode(userId,gameCode,operatorCode,request);
}
private UserGameHistory getRoundHistory(RoundRecordDocument round) {
if (round == null) {
return null;
}
return historyRepository
.findByUserIdAndGameCodeAndOperatorCodeAndRoundId(round.getInternalUserId(),round.getGameCode(),round.getoperatorCode(),round.getCycleId(),SINGLE_RESULT)
.get()
.findFirst()
.orElse(null);
}
存储库:
@Repository
public interface UserGameHistoryRepository extends CrudRepository<UserGameHistory,UserGameHistoryId> {
Page<UserGameHistory> findByUserIdAndGameCodeAndOperatorCode(String userId,Pageable pageable);
Page<UserGameHistory> findByUserIdAndGameCodeAndOperatorCodeAndRoundId(String userId,String roundId,Pageable pageable);
}
实体模型:
@Data
@Entity
@NoArgsConstructor
@AllArgsConstructor
@Table(name = UserGameHistory.TABLE_NAME)
@IdClass(UserGameHistoryId.class)
public class UserGameHistory {
public static final String TABLE_NAME = "user_game_history";
public static final String COLUMN_START_TIME_NAME = "roundStartTime";
@Id
@JsonIgnore
private String userId;
@Id
@JsonIgnore
private String gameCode;
@Id
@JsonIgnore
private String operatorCode;
@Id
private String roundId;
/**
Quantity of other fields:
5 - String
5 - Double
2 - Timestamp
1 - Boolean
*/
}
@Data
@NoArgsConstructor
public class UserGameHistoryId implements Serializable {
private String userId;
private String gameCode;
private String operatorCode;
private String roundId;
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)