β

Vert.x学习——性能对比

孤岛旭日的个人空间 362 阅读

<p> Vert.x,一个很强大的高性能分布式框架,套用官网的说法: “Vert.x is a lightweight, high performance application platform for the JVM that's designed        for modern mobile, web, and enterprise applications.” Vert.x的中文资料不多,学习主要从官网文档、示例及youtube的一些视频入手。 开始前先做个与servlet(基于tomcat)的性能对比,运行echo服务(源码: <a href="http://b.sunisle.org/wp-content/uploads/2014/02/echo_test.7z" rel="nofollow"> echo_test </a> ): 测试服务器是我的surface pro 2,i5低电版、4G内存、固态硬盘,测试工具为jmeter。 先看500线程50次循环: </p> <p> <a href="http://b.sunisle.org/wp-content/uploads/2014/02/servlet_tomcat_500_50_config.png" rel="nofollow"> <img alt="servlet_tomcat_500_50_config" height="108" src="/imgr?src=http%3A%2F%2Fstatic.oschina.net%2Fuploads%2Fimg%2F201411%2F05110230_DYxT.png&r=http%3A%2F%2Fmy.oschina.net%2Fgudaoxuri%2Fblog%2F340926" width="239"/> </a> </p> <p> <a href="http://b.sunisle.org/wp-content/uploads/2014/02/servlet_tomcat_500_50_result_线程220.png" rel="nofollow"> <img alt="servlet_tomcat_500_50_result_线程220" height="65" src="/imgr?src=http%3A%2F%2Fstatic.oschina.net%2Fuploads%2Fimg%2F201411%2F05110230_k203.png&r=http%3A%2F%2Fmy.oschina.net%2Fgudaoxuri%2Fblog%2F340926" width="742"/> </a> </p> <p> 此时tomcat开发220多个线程,有4%多的错误率,吞吐量为544/s   然后再看1000线程50次循环: </p> <p> <a href="http://b.sunisle.org/wp-content/uploads/2014/02/servlet_tomcat_1000_50_config.png" rel="nofollow"> <img alt="servlet_tomcat_1000_50_config" height="110" src="/imgr?src=http%3A%2F%2Fstatic.oschina.net%2Fuploads%2Fimg%2F201411%2F05110230_fDHr.png&r=http%3A%2F%2Fmy.oschina.net%2Fgudaoxuri%2Fblog%2F340926" width="244"/> </a> </p> <p> <a href="http://b.sunisle.org/wp-content/uploads/2014/02/servlet_tomcat_1000_50_result_线程220.png" rel="nofollow"> <img alt="servlet_tomcat_1000_50_result_线程220" height="65" src="/imgr?src=http%3A%2F%2Fstatic.oschina.net%2Fuploads%2Fimg%2F201411%2F05110230_ZQPW.png&r=http%3A%2F%2Fmy.oschina.net%2Fgudaoxuri%2Fblog%2F340926" width="737"/> </a> </p> <p> 此时错误率升到了24%,90%用户访问超过了2s,已经超过极限了。 最后看一下2000线程50次循环: </p> <p> <a href="http://b.sunisle.org/wp-content/uploads/2014/02/vertx_2000_50_config.png" rel="nofollow"> <img alt="vertx_2000_50_config" height="110" src="/imgr?src=http%3A%2F%2Fstatic.oschina.net%2Fuploads%2Fimg%2F201411%2F05110230_ano5.png&r=http%3A%2F%2Fmy.oschina.net%2Fgudaoxuri%2Fblog%2F340926" width="239"/> </a> </p> <p> <a href="http://b.sunisle.org/wp-content/uploads/2014/02/servlet_tomcat_nio_2000_50_result_线程180.png" rel="nofollow"> <img alt="servlet_tomcat_nio_2000_50_result_线程180" height="55" src="/imgr?src=http%3A%2F%2Fstatic.oschina.net%2Fuploads%2Fimg%2F201411%2F05110231_C7LY.png&r=http%3A%2F%2Fmy.oschina.net%2Fgudaoxuri%2Fblog%2F340926" width="736"/> </a> </p> <p> 打开了nio后tomcat上的结果,早知nio打开后性能提升很大,果不其然! <a href="http://b.sunisle.org/wp-content/uploads/2014/02/vertx_2000_50_result_线程18.png" rel="nofollow"> <img alt="vertx_2000_50_result_线程18" height="65" src="/imgr?src=http%3A%2F%2Fstatic.oschina.net%2Fuploads%2Fimg%2F201411%2F05110231_HeDy.png&r=http%3A%2F%2Fmy.oschina.net%2Fgudaoxuri%2Fblog%2F340926" width="718"/> </a> </p> <p> 最后这个是vert.x的结果了,vert.x只开了18个线程,结果上看略高于打开nio后的tomcat,但要说明的是我的压测机配置不够,分配2000线程时占满了CPU,而服务器没什么资源压力,换高配的机子来运行jmeter的话肯定更好。   这是一个不严谨的对比,但结果还是有一定参考价值: 1.nio对性能的提升很关键,vert.x的io基于netty,而它正是用nio2; 2.vert.x的性能的确很彪悍,事件驱动、nio2!   如果有时间可以进一步对比一下用jetty运行的servlet、nodejs、vert.x的netServer。 </p>

作者:孤岛旭日的个人空间
孤岛旭日的博客
原文地址:Vert.x学习——性能对比, 感谢原作者分享。