设为首页 收藏本站
查看: 508|回复: 0

[经验分享] 转: Street Fight: PHP vs Java(Part 1)

[复制链接]
发表于 2017-4-8 08:45:43 | 显示全部楼层 |阅读模式
Street Fight: PHP vs Java (Part 1)     

Please welcome our newest regular GJ blogger: The Blackdood
Ooooo! fight! fight! fight!.
This is a fight that has been going on for as long as I can remember. Some say Java is too heavy, some say PHP is too light. I'm here to tell you how it is.
To be fair, I was first a Perl programmer, and that didn't last long. I then moved to PHP3. I was a PHP developer up until about a year ago, straight through PHP5. Now, I develop for both. I have managed teams of both PHP developers and Java developers, and developed large scale applications in both.
PHP has come a long way since the days of version 3. The new object model is a step in the right direction, and OO programming is no longer as big of a performance hog. As a result, a ton of PHP frameworks have started popping up. The one I've used the most is Symfony (http://www.symfony-project.com), it's basically a port of RoR. The Java framework I am using is WebWork (http://www.opensymphony.com/webwork/).
This is the first article of many to come. This first one will cover VERY basic performance results, and we'll get more detailed as time goes on and users request. What I will be focusing on is ACTUAL development with, not the actual benchmark results
Now, let's get the numbers out of the way. I did some minor benchmarking, but we all know that benchmarks don't really prove much as it can EASILY be swayed in one direction or another. These are just very basic operations, not going to benchmark the frameworks because that's unfair. I'll explain why later.
I tested : Apache Webserver + mod_php5 and Zend vs Resin 3.0.19 w/ JDK5 on a Dual Core Intel Mac 1.5 gigs of RAM.
For testing I used ab (apachebench) which comes default with every apache installation. Basically a "dumb" client that hits a URL as fast as it can.
The command was:
ab -c 50 -n 10000

Which means, do 50 requests at a time, and complete 10,000 requests. This test isn't exactly the best because it's not really doing anything. Really only testing who can loop faster. Results are interesting though.

The scripts:
JSP:

<%
for(Integer i =0; i < 10000; i++)
{
out.println((i % 10));
}
%>
PHP

<?php
for($i =0; $i < 10000; $i++)
{
echo $i % 10;
}
?>

PHP Results:
260.68 requests per second. Took 38 seconds to service 10000 requests (50 concurrent users at a time)

/resin/webapps/benchmarks jgagner$ ab -c 50 -n 10000 http://localhost/~jgagner/benchmark1.php
This is ApacheBench, Version 1.3d <$Revision: 1.73 $> apache-1.3
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Finished 10000 requests
Server Software:        Apache/1.3.33                                      
Server Hostname:        localhost
Server Port:            80
Document Path:          /~jgagner/benchmark1.php
Document Length:        10000 bytes
Concurrency Level:      50
Time taken for tests:   38.361 seconds
Complete requests:      10000
Failed requests:        0
Broken pipe errors:     0
Total transferred:      101834793 bytes
HTML transferred:       100161954 bytes
Requests per second:    260.68 [#/sec] (mean)
Time per request:       191.80 [ms] (mean)
Time per request:       3.84 [ms] (mean, across all concurrent requests)
Transfer rate:          2654.64 [Kbytes/sec] received
Connnection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    19   28.6      4   166
Processing:     9   171  102.5    163  1117
Waiting:        0   170  102.9    162  1116
Total:          9   190  101.8    173  1117
Percentage of the requests served within a certain time (ms)
  50%    173
  66%    208
  75%    233
  80%    250
  90%    298
  95%    386
  98%    490
  99%    543
100%   1117 (last request)


JSP results:

1010.61 requests per second, or 9.85 seconds to service 10,000 requests (50 at a time)
/resin/webapps/benchmarks/WEB-INF jgagner$ ab -c 50 -n 10000 http://localhost:8080/benchmarks/benchmark1.jsp
This is ApacheBench, Version 1.3d <$Revision: 1.73 $> apache-1.3
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Finished 10000 requests
Server Software:        Resin/3.0.19                                       
Server Hostname:        localhost
Server Port:            8080
Document Path:          /benchmarks/benchmark1.jsp
Document Length:        20000 bytes
Concurrency Level:      50
Time taken for tests:   9.895 seconds
Complete requests:      10000
Failed requests:        0
Broken pipe errors:     0
Total transferred:      202307479 bytes
HTML transferred:       200116165 bytes
Requests per second:    1010.61 [#/sec] (mean)
Time per request:       49.47 [ms] (mean)
Time per request:       0.99 [ms] (mean, across all concurrent requests)
Transfer rate:          20445.42 [Kbytes/sec] received
Connnection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0     0    1.5      0    26
Processing:     5    49   44.8     46   618
Waiting:        2    48   44.8     45   617
Total:          5    49   44.7     46   618
Percentage of the requests served within a certain time (ms)
  50%     46
  66%     49
  75%     51
  80%     52
  90%     60
  95%     86
  98%    203
  99%    313
100%    618 (last request)

Wow, amazing isn't it!? Remember kids, benchmarks don't always tell the whole story. We'll find out why next episode. If you have any comments or suggestions you may write me, jerome AT blackdood DOT com.
Holla back,  youngin.
Blackdood

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-361726-1-1.html 上篇帖子: 编写PHP扩展函数的参数类型绑定 下篇帖子: PHP中session问题的解决方案集锦
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表