• spring5 webflux测试


    ServerResponse方式

    @Configuration
    public class RouterFunctionConfiguration {
    
        @Bean
    //    @Autowired
        public RouterFunction<ServerResponse> personFindAll(UserRepository userRepository){
    
    
            return RouterFunctions.route(RequestPredicates.GET("/person/find/all"),
                    request ->{
                        Collection<User> users = userRepository.findAll();
    
                        Flux<User> userFlux = Flux.fromIterable(users);
                        return ServerResponse.ok().body(userFlux,User.class);
                    });
        }
    }

    测试

    
    
    @Test
    public void threadTestOrderBy() throws InterruptedException {

    final Long id=141284830240768L;
    int threadCount=100000;
    final CountDownLatch begin = new CountDownLatch(1);
    final CountDownLatch end = new CountDownLatch(threadCount);
    final int[] result={0,0};
    final Object lock = new Object();
    ExecutorService executorService = Executors.newFixedThreadPool(100);
    Long time1=System.currentTimeMillis();
    for (int i = 0; i < threadCount; i++) {
    Thread thread = new Thread(new Runnable() {
    @Override
    public void run() {
    try {
    begin.await();
    HttpParamsVo httpParamsVo = new HttpParamsVo(new HttpSecretVo(appKey,appSecret),params);
    String resultS = HttpClientSecretSendUtil.get(url, httpParamsVo);
    synchronized(lock){
    result[0]++;
    }
    } catch (Exception ex) {
    synchronized(lock) {
    result[1]++;
    }
    ex.printStackTrace();
    }finally{
    end.countDown();
    }
    }
    });
    executorService.submit(thread);
    }
    System.out.println(threadCount+"个线程开始");
    begin.countDown();
    end.await();
    Long time2=System.currentTimeMillis();
    System.out.println("耗时: "+(time2-time1)/1000+"秒");
    System.out.println(threadCount+"个线程更新结束");
    System.out.println("成功"+result[0]+",失败"+result[1]);
    }
    
    

    耗时

    servlet方式

    @GetMapping("/person/find/all")
        @ResponseBody
        public Collection<User> findAll(){
            return this.userRepository.findAll();
        }

    测试同上

    结果

    总结100W个线程的情况下

    spring 5提供的 webFlux 相比 servlet模型 慢了17秒

  • 相关阅读:
    android编译全过程
    Android APK反编译得到Java源代码和资源文件
    获取Android的Java源代码并在Eclipse中关联查看的最新方法《转载》
    定制ROM,添加apk文件报错。
    Ubuntu下下载编译android源码
    poj 2714 Random Walk
    hdu 3829 Cat VS Dog
    第九场组队赛总结
    2012 MUTC 9 总结
    hdu 1100 Trees Made to Order
  • 原文地址:https://www.cnblogs.com/zfzf1/p/8507360.html
Copyright © 2020-2023  润新知