use of info.xiancloud.core.util.LOG in project xian by happyyangyuan.
the class JedisTestDistributedLock method execute.
@Override
public UnitResponse execute(UnitRequest msg) {
int number = msg.get("number", int.class, 10000);
final CountDownLatch startCountDownLatch = new CountDownLatch(1);
final CountDownLatch finishCountDownLatch = new CountDownLatch(number);
final List<Long> consumeTimes = new CopyOnWriteArrayList<>();
for (int i = 0; i < number; i++) {
int _i = i;
ThreadPoolManager.execute(() -> {
try {
startCountDownLatch.await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
long startTime = System.nanoTime();
// Redis Lock
DistributedLockSynchronizer.call("QPS_" + _i, 3, () -> {
return null;
}, 3);
// ZK Lock
// try
// {
// Synchronizer.call("QPS_" + _i, () -> {
// return null;
// }, 3L);
// }
// catch (Exception e)
// {
// LOG.error(e);
// }
finishCountDownLatch.countDown();
long endTime = System.nanoTime();
consumeTimes.add(endTime - startTime);
});
}
try {
startCountDownLatch.countDown();
finishCountDownLatch.await();
} catch (Exception e) {
LOG.error(e);
}
long totalConsumeTime = 0;
for (long consumeTime : consumeTimes) totalConsumeTime += consumeTime;
long avgConsumeTime = totalConsumeTime / number;
LongSummaryStatistics intSummaryStatistics = consumeTimes.stream().collect(Collectors.summarizingLong(value -> value));
String log = String.format("QPS, 加锁解锁, 任务数量: %s, 累计耗时: %s, %s, 平均耗时:%s, %s, %s", number, totalConsumeTime, totalConsumeTime / 1000000, avgConsumeTime, avgConsumeTime / 1000000, intSummaryStatistics);
LOG.info(log);
UnitResponse unitResponseObject = SyncXian.call("cache", "cacheKeys", new JSONObject() {
{
put("pattern", "LOCK_QPS_*");
}
});
if (unitResponseObject.succeeded() && unitResponseObject.getData() != null) {
Set<String> keys = unitResponseObject.getData();
LOG.info(String.format("分布锁剩余数量: %s", keys.size()));
}
SyncXian.call("diyMonitor", "jedisLockMonitor", new JSONObject() {
{
}
});
return UnitResponse.success(log);
}
Aggregations