Commit e2e93b03 authored by xiaoguang.xu's avatar xiaoguang.xu

耗时统计, 看看哪里满了.

parent 0ca907cb
...@@ -5,6 +5,7 @@ import cn.quantgroup.xyqb.entity.UserHashMapping; ...@@ -5,6 +5,7 @@ import cn.quantgroup.xyqb.entity.UserHashMapping;
import cn.quantgroup.xyqb.model.JsonResult; import cn.quantgroup.xyqb.model.JsonResult;
import cn.quantgroup.xyqb.repository.IUserRepository; import cn.quantgroup.xyqb.repository.IUserRepository;
import cn.quantgroup.xyqb.util.encrypt.MD5Util; import cn.quantgroup.xyqb.util.encrypt.MD5Util;
import com.google.common.base.Stopwatch;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BatchPreparedStatementSetter; import org.springframework.jdbc.core.BatchPreparedStatementSetter;
...@@ -19,6 +20,7 @@ import java.util.ArrayList; ...@@ -19,6 +20,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
@Slf4j @Slf4j
@RestController @RestController
...@@ -50,12 +52,15 @@ public class SyncHashController { ...@@ -50,12 +52,15 @@ public class SyncHashController {
.execute(() -> { .execute(() -> {
Long startPosition = startUserId; Long startPosition = startUserId;
while (isContinue) { while (isContinue) {
Stopwatch started = Stopwatch.createStarted();
Long endPosition = startPosition + step; Long endPosition = startPosition + step;
List<User> users = userRepository.findByIdBetween(startPosition, endPosition); List<User> users = userRepository.findByIdBetween(startPosition, endPosition);
if (users.isEmpty()) { if (users.isEmpty()) {
log.info("没有数据了. 结束了"); log.info("没有数据了. 结束了");
return; return;
} }
log.info("查询用户需要的时间 : {}ms", started.elapsed(TimeUnit.MILLISECONDS));
started = started.reset().start();
List<UserHashMapping> userHashMappings = new ArrayList<>(); List<UserHashMapping> userHashMappings = new ArrayList<>();
users.forEach(user -> { users.forEach(user -> {
UserHashMapping userHashMapping = new UserHashMapping(); UserHashMapping userHashMapping = new UserHashMapping();
...@@ -63,7 +68,8 @@ public class SyncHashController { ...@@ -63,7 +68,8 @@ public class SyncHashController {
userHashMapping.setPhoneNoMd5(MD5Util.build(user.getPhoneNo())); userHashMapping.setPhoneNoMd5(MD5Util.build(user.getPhoneNo()));
userHashMappings.add(userHashMapping); userHashMappings.add(userHashMapping);
}); });
log.info("遍历计算md5&crc32需要的时间 : {}ms", started.elapsed(TimeUnit.MILLISECONDS));
started = started.reset().start();
String sql = "INSERT INTO `user_hash_mapping` ( `user_id`, `phone_no_md5`, `phone_no_md5_short`) VALUES (?,?,?);"; String sql = "INSERT INTO `user_hash_mapping` ( `user_id`, `phone_no_md5`, `phone_no_md5_short`) VALUES (?,?,?);";
jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
@Override @Override
...@@ -80,6 +86,8 @@ public class SyncHashController { ...@@ -80,6 +86,8 @@ public class SyncHashController {
} }
}); });
log.info("batchUpdate需要的时间 : {}ms", started.elapsed(TimeUnit.MILLISECONDS));
log.info("来一波,start:{},end:{}", startPosition, endPosition); log.info("来一波,start:{},end:{}", startPosition, endPosition);
startPosition = users.get(users.size() - 1).getId() + 1; startPosition = users.get(users.size() - 1).getId() + 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment