netty确实牛逼,性能比肩redis,实践压测

程序准备

redis部署

redis客户端

package org.example;

import io.netty.channel.SingleThreadEventLoop;
import io.netty.channel.nio.NioEventLoopGroup;
import org.redisson.Redisson;
import org.redisson.api.RAtomicLong;
import org.redisson.api.RFuture;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.redisson.config.TransportMode;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.concurrent.*;

// 按两次 Shift 打开“随处搜索”对话框并输入 `show whitespaces`,
// 然后按 Enter 键。现在,您可以在代码中看到空格字符。
public class Main {

    private static final ExecutorService work = Executors.newSingleThreadExecutor();

    public static void main(String[] args) throws InterruptedException {


        int requests = Integer.parseInt(args[0]) ;

        int threads = args.length > 1 ? Integer.parseInt(args[1]) : 1;

        Config config = new Config();
        config.setTransportMode(TransportMode.NIO); // 默认是NIO的方式
        config.useSingleServer()
                //可以用"rediss://"来启用SSL连接,前缀必须是redis:// or rediss://
                .setAddress("redis://192.168.253.148:6379")
//                .setPassword("123456")
        ;
        config.setThreads(threads);
        config.setNettyThreads(threads);
        config.setEventLoopGroup(new NioEventLoopGroup(threads));



        RedissonClient redissonClient = Redisson.create(config);

        RAtomicLong key_long = redissonClient.getAtomicLong("key_long");

        key_long.set(0);

        CountDownLatch latch = new CountDownLatch(requests);
        long start = System.currentTimeMillis();
        for(int i = 0; i < requests; i++)
        {
            RFuture<Long> future = key_long.incrementAndGetAsync();

            work.submit(
                    () ->
                    {
                        Long tmp;
                        try {
                            tmp = future.get();
                            latch.countDown();
                            System.out.println("第" + tmp + "次请求");

                        } catch (InterruptedException | ExecutionException e) {
                            e.printStackTr
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

无心六神通

你的鼓励是我持续创作的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值