连接到本地redis,莴苣需要近5000毫秒,但绝地只需要30毫秒
我使用带有lombok依赖项的默认spring boot starter:
我的代码:
@Component
@Slf4j
class LettuceRunner implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
StopWatch watch = new StopWatch();
RedisClient redisClient = RedisClient.create("redis://localhost:6379");
watch.start();
StatefulRedisConnection<String, String> connection = redisClient.connect();
watch.stop();
log.info("lettuce : {} ms", watch.getLastTaskTimeMillis());
connection.close();
redisClient.shutdown();
}
}
@Component
@Slf4j
class JedisRunner implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
StopWatch watch = new StopWatch();
watch.start();
Jedis jedis = new Jedis("localhost");
jedis.get("redis_key");
watch.stop();
log.info("jedis : {} ms", watch.getLastTaskInfo().getTimeMillis());
}
}
结果是:
2020-08-14 17:02:28.236信息21760---[main]com.example.demo.jedisrunner:jedis:27 ms 2020-08-14 17:02:33.318信息21760---[main]com.example.demo.lettucerunner:莴苣:4815 ms
1条答案
按热度按时间kqlmhetl1#
因为莴苣用的是netty,它花了大量的时间在netty上发起事情。
查看日志,如您所见,花费的大部分时间都在io.netty包中: