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

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

parent 0ca907cb
......@@ -5,6 +5,7 @@ import cn.quantgroup.xyqb.entity.UserHashMapping;
import cn.quantgroup.xyqb.model.JsonResult;
import cn.quantgroup.xyqb.repository.IUserRepository;
import cn.quantgroup.xyqb.util.encrypt.MD5Util;
import com.google.common.base.Stopwatch;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
......@@ -19,6 +20,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
@Slf4j
@RestController
......@@ -50,12 +52,15 @@ public class SyncHashController {
.execute(() -> {
Long startPosition = startUserId;
while (isContinue) {
Stopwatch started = Stopwatch.createStarted();
Long endPosition = startPosition + step;
List<User> users = userRepository.findByIdBetween(startPosition, endPosition);
if (users.isEmpty()) {
log.info("没有数据了. 结束了");
return;
}
log.info("查询用户需要的时间 : {}ms", started.elapsed(TimeUnit.MILLISECONDS));
started = started.reset().start();
List<UserHashMapping> userHashMappings = new ArrayList<>();
users.forEach(user -> {
UserHashMapping userHashMapping = new UserHashMapping();
......@@ -63,7 +68,8 @@ public class SyncHashController {
userHashMapping.setPhoneNoMd5(MD5Util.build(user.getPhoneNo()));
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 (?,?,?);";
jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
@Override
......@@ -80,6 +86,8 @@ public class SyncHashController {
}
});
log.info("batchUpdate需要的时间 : {}ms", started.elapsed(TimeUnit.MILLISECONDS));
log.info("来一波,start:{},end:{}", startPosition, endPosition);
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