毕
课题名称
系 部
专 业
班 级
学 号
姓 名
指导教师
2017年4月 14 日
Performance Comparison of PHP and JSP as Server-Side
Scripting Languages
MaterialSource:Notesin Computer Science
Author:Sc ott Trent;Michiaki Tatsubori;Toyotaro Suzumura;Akihiko Tozawa and Tamiya Onodera
1 Introduction
The dynamic scripting language PHP(PHP Hypertext Preprocessor) has becomeenormously popular for implementing lightweight web applications,and is widely used toaccess databases and other middleware.Apache module popularity surveys performed bySecurity Space in October 2007 indicate that 37%of Apache servers have PHP supportenabled,making it the most popular Apache module by 10 percentage points.Businesses arequickly realizing the powerful combinatio n of a service oriented architecture environmentwith dynamic scripting languages like PHP.However,we believe that there are still criticalperformance issues involving PHP which remain to be investigated.
This paper focuses on the use of dynamic scripting languages to implement web serverfront-end interfaces. This corresponds with the way that the industry standard web serverperformance benchmark SPECweb2005 utilizes PHP and JSP(JavaServer Pages).In this case,scripts are used for the implementation of dynamic page generation, rather than therealization of complex business logic. This contrasts with the traditional uses of complexJSP-based business logic implementation.While there are numerous studies on dynamic webcontent, this paper complements these studies with detailed analysis focusing on PHP.Forexample, following the performance study on CGI (Common Gateway Interface)based webservers for dynamic content by Yeager &McGrath back in 1995, researchers andpractitioners have been examining the performance of more recent dynamic Webcontentgeneration technologies. These works, however, handle application scenario s where servletfront-ends implement relatively complex business logic.
Although Warner and Worley discuss the importance of also using PHP withSPECweb2005, to the best of the author’s knowledge, this paper is the first to publish adetailed analysis of SPECweb2005 experimental results using both PHP and JSP. Thedetailed analysis of PHP and JSP performance based on SPECweb2005 offered by this paperenables designers and implementers of web servers to understand the relative performanceand through put of different versions and configurations ofPHP and JSP.
1
2 Multi-tier Web Server Architecture: Lightweight Front-EndUsing PHP/JSP
Developers typically use PHP to implement a front-end interface to dynamic Webcontent generators,which are combined with web server software and back-end servers toprovide dynamic content. The web server directly handles requests for static content andforwards requests for dynamic content to the dynamic content generator. The dynamiccontent generator, supported by back-end servers, executes code which realizes the businesslogic of a web site and stores dynamic state. Back-end servers may be implemented as astraight-forward database,or may be more complex servers handling the business logic of theweb site.The front-end implementation may vary from heavy-weight business logic handlersto lightweight clients composing content received from back-end servers.
This paper focuses on multi-tier web site development scenarios utilizing suchlightweight front-ends, supported by one or more layers of heavy-weight back-ends. Thisassumption is reasonable when considering Service-Oriented environments where PHPscripts are used to implement a "mash-up"of services provided elsewhere, in addition to thecase of simple web sites such as bulletin boards where PHP scripts are just a wrapper to adatabase. Within the scenarios described in this paper, the dynamic content generatorprovides client implementation in addition to page composition. It connects to the back-endserver through a network using either standard protocols such as HTTP orapp licatio n/middleware-spec ific p rotoco ls.
JSP technology can be considered an alternative to PHP in implementing suchfront-ends.While it is part of the Java Servlet framework,developers typically use JSP toimplement lightweight front-ends. Both PHP and JSP allow developers to write HTMLembedded code. In fact, although there are language inherent differences between PHP andJava, the use of PHP scripts and JSP files can be very similar.
The objective of the experiments detailed in this paper is to measure the performance oflightweight front-end dynamic content generation written in PHP and JSP with popular webservers such as Apache and Lighttpd.This web server architecture scenario involves userswho access a web server with pages written in plain static HTML, as well as JSP and PHPscripts which mix scripting language with HTML code.The configuration assumed withinthe paper is a typical one,where web server software, such as Apache,distinguishes betweenpure HTML, JSP, and PHP respectively with suffixes such as .html, .jsp, and .php.HTMLcode is directly returned to the requesting end-user’s web browser,where JSP and PHP pages
2
are respectively parsed by the Tomcat script engine and the PHP runtime engine which bothprovide pure HTML which is forwarded to the end-user on a remote system.A common pointbetween JSP and PHP is that implementations which perform well have a dynamicallycompiled and cached byte code. For example, the Java runtime used by the Tomcat scriptengine which we used performs much better when the Just-in-Time(JIT)compiler is enabledto create efficient cached native runtime code. Similarly, the Zend PHP runtime we usedalso performs significantly better when the Alternative PHP Cache (APC) is enabled, inwhich APC stores PHP byte codes compiled from the script source code in shared memoryfor future reuse.
3 Language Runtime Performance Micro Benchmarking
To understand the difference in performance characteristics between PHP and Java at thelanguage runtime level we compared the following engines using a series of microb enc hmark te st s:
-PHP 4.4.7
-PHP 5.2.3
-Java 5 with Just-In-Time(JIT)compilation(IBM J9 VM 1.5.0 Build 2.3)
-Java 5 without Just-In-Time(JIT)comp ilation(same as above)
The PHP language framework allows developers to extend the language with libraryfunctions written in C.These functions,which are known as "extensions",are then availableto be used within PHP scripts.The PHP runtime provides a variety of extensions for stringmanipulation, file handling,networking,and so forth. Since our first goal was to understandthe performance of the PHP runtime itself,we conducted our experiments without the use ofextensions.We developed the fo llowing micro benchmarks:
-A quick sort benchmark which sorts 100 integers,
-A Levenshtein benchmark which measures the similarity between two strings of 56characte rs,
-AFibonaccibenchmark which calculates the 15th value in a Fibonacci series withtwo arb itrary starting values.
These PHP benchmarks were implemented entirely with PHP language primitives andavoided the use of PHP extensions. The Java versions also focused on using languageprimitives rather than standard classe s.We compared the total run time o f executing each test10,000 times with each engine.We also executed each benchmark an additional 10,000 timesas a warm-up,before the measured test.This prevents Java just-in-time compilation overheadfrom impacting the score in the Java tests.We ran the experiment on an Intel Pentium 4 CPU
3
at 3.40 GHz with 3 GB RAM Memory,with the Linux 2.6.17 kernel.
This test demonstrates large performance differences between each of themeasuredscripting languages and implementations. The experimental results in Figure 1 indicate that“Java 5 with JIT compilation”performs the best, followed“Java 5 without JIT compilation”,“PHP 5.2.3”, and“PHP 4.4.7” in all measured cases. Java 5 with JIT demonstrated nearlythree orders of magnitude better performance due to the use of efficiently generated nativecode. It is also obvious that PHP 5.2.3 has a two to three times performance impro vementover PHP 4.4.7 with the measured computations. Secondly to determine the performanceeffect of PHP extensions compared with Java class methods,we developed and tested threeadditional micro benchmarks: regular expression matching,MD5 encoding,and Levenshteincomparison. For regular expression matching, the Perl Compatible Regular Expressionextension(through the preg_match() function)was used in PHP, and the java. util.regexpackage was used in Java. For MD5 encoding, the MD5 extension was used in PHP andjava.security. MessageDigest was used in Java.This experiment does not compare exactlythe same logic,but rather demonstrates that the use of PHP extensions is competitive withJava using just-in-time compilation,as seen in Figure 2.
Although the pure script experiment showed three orders of magnitude differencebetween the performance of various implementations of Java and PHP, the use of PHPextensions (written in C) and compiled Java class libraries show much less variation. In theextreme, the regular expression test showed a maximum performance difference of about fivetimes between Java and PHP,on the other end, the MD5 test results were nearly equivalentbetween Java and PHP.Thus a inherent performance risk of interpreted scripted languagessuch as PHP can be overcome with the use of efficient library functions such as PHPextensions written in C.
4
PHP和JSP作为服务器脚本语言的性能比较
资料来源:计算机科学讲义
作者Scott TrentM ichiaki TatsuboriToyotaro S uzumuraAkihiko To zawa和TamiyaOnodera
1简介
动态脚本语言P HP P HP超文本预处理器已经成为非常流行的轻量级Web执行应用程序并广泛用于访问数据库和其他中间件。 2007年10月流行的Apache模块安全空间进行的调查表明 37%的Ap ac he服务器支持P HP功能 以10个百分点使它成为最流行的Ap ac he模块。企业正迅速实现与动态脚本语言如PHP的面向服务的体系结构环境的强大组合。然而我们相信仍然有重要的性能问题涉及到P HP它仍有待于被调查。
本文重点介绍了动态脚本语言的使用来实现Web服务器的前端接口。与此对应的方式该行业标准的Web服务器性能的基准S PECweb2005利用PHP和JS PJavaS erver页面。在这种情况下脚本是用于执行动态页面生成而不是复杂的业务逻辑的实现。与此相反的传统用途是基于JSP的复杂的业务逻辑实现。虽然有许多动态网页内容的研究本文补充了这些研究的详细分析重点在于P HP中。例如下面就C GI 通用网关接口基于Web服务器的动态内容由耶格尔麦格拉思可追溯到1995年的性能研究研究人员和从业者一直在研究最近的动态的WebC onte nt技术性能。这些作品然而处理应用程序方案在servlet前端实现相对复杂的业务逻辑。
虽然华纳和沃利也使用P HP与S P EC web 2005,以作者所知的重要性本文是首次发布了使用P HP和J S P的S P EC web 2005实验结果的详细分析。P HP和J S P的性能的详细分析是基于本文件所提供的S PECweb2005使设计者和实施者了解Web服务器的相对性能并通过把不同版本的P HP和J S P进行配置。
2多层We b服务器架构使用PHP/JSP的轻量级前端
开发人员通常使用P HP来实现一个生成动态Web内容的前端界面这与Web服务器软件和后端服务器相结合提供动态内容。该网站的服务器直接处理静态内容并转发请求动态内容生成动态内容。后端服务器支持动态内容生成执行代码来实现一个网站和商店的动态状态的业务逻辑。后端服务器可以作为一个直接的数据库来实现或者可能更复杂的服务器处理该网站的业务逻辑。前端的执行可能有所不同于重量级的业务逻
5
辑程序来处理从后端服务器接收轻量级客户端的内容。
本文重点介绍多层Web站点开发利用这种由一个或多个重量级后端层支持轻量级的前端。当考虑到面向服务的环境中P HP脚本用来实现提供其他地方的一个“混搭”的服务这种假设是合理的。除了简单的网站情况下例如公告板中P HP脚本只是一个包装到一个数据库。在本文中所描述的场景中动态内容生成器提供动态内容页组成除了客户端实现。它通过使用标准协议诸如HTTP或应用程序/中间件特定协议连接到后端服务器。
JSP技术可以被认为是对PHP在执行这些前端的一种选择。虽然它是Java Servlet的框架的一部分开发人员通常使用J S P来实现轻量级前端。 P HP和J SP允许开发人员可以编写HTML嵌入代码。事实上虽然P HP和Java之间有着固有的不同之处但P HP的脚本和J S P文件在使用上的差异可能会非常相似。
在这份文件中详细介绍了实验的目的是衡量结合诸如Apac he和Lighttpd的流行Web服务器使用P HP和J S P编写的轻量级前端动态内容生成器性能。此Web服务器架构方案涉及用户访问使用纯静态页面HTML编写的Web服务器 以及JS P和PHP脚本混合脚本语言和HTML代码。本文内承担的配置是一个典型的其中Web服务器软件如Ap ac he后缀与纯粹的H TM L JS P和PHP等之间的区别分别是.html .j sp和.php。 HTM L代码是直接返回到最终用户请求的网络浏览器在JS P和PHP页面分别由Tomcat的脚本引擎和PHP运行时引擎提供纯HTML转发给最终在远程系统的用户进行解析。 J S P和P HP之间的共同点是这些执行良好的实现有一个动态编译和缓存的字节码。例如 Ja va运行时使用To mca t的脚本引擎当实时JI T编译器功能来创建有效的本地缓存的运行时代码时我们执行越好。同样我们使用了Ze nd的P HP运行时当可替代的P HP缓存AP C启用则执行明显好从共享内存中AP C存储P HP字节码 以便将来重用脚本源代码。
3语言运行时性能微标杆
为了了解P HP语言运行时水平在性能特点上的不同我们比较了用微型基准测试一下引擎
-P HP的4.4.7
-P HP的5.2.3
-Java 5与实时JIT编译IBM的J9虚拟机1.5.0 Build 2.3
-Java 5不只是实时JIT编译同上
P HP语言框架允许开发人员扩展这些用C语言编写的功能这些功能被称为“扩展”称为库函数的语言然后提供给P HP脚本内使用。 P HP运行时提供了多种扩展的字符串操作文件处理 网络等等。
6
由于我们的首要目标是了解P HP运行时本身的性能我们实施的实验没有使用扩展。
我们制定了以下微基准
-以100个整数进行快速排序的基准
-一个Le ve ns hte in基准检测两行56个字符的字符串的相似性
-一个斐波纳契计算基准在一个任意两个初始值斐波纳契数列第15的值。
这些P HP的基准完全用P HP原始语言实现和避免了P HP扩展的使用。Ja va的版本也侧重于利用原始的语言而不是标准类的语言。我们比较了每个引擎执行每个测试10000次的总运行时间。每个测试前我们也执行作为热身的额外10000次测量基准。这可以防止在Java影响得分的测试中即时编译。我们在3.40 GB的RAM内存 4CPU的Inte l奔腾与L inux 2.6. 17内核上运行实验。
此测试演示测量之间的脚本语言和实现的巨大性能差异。 图1中的实验结果表明“JIT编译的Java 5”性能最好在所有测量案件中“没有JIT编译的Java 5” “PHP的5.2.3” “PHP的4.4.7”次之。 Java 5基于有效地生成本地代码使用结合JIT演示了近三个数量级更好性能的订单。显而易见的是 P HP的5.2.3有两倍至三倍的性能改进超过实际测量计算的P HP的4.4.7。其次 以P HP与Ja va类的方法相比确定扩展性能的影响我们开发和测试三种额外的微基准常规的表达式匹配MD5编码和Le ve ns hte in比较。对于常规表达式匹配 P er l兼容常规表达式扩展通过pre g_matc h()函数使用PHP和在Java中使用java.util.re gex包。对于MD5编码MD5的扩展也在PHP中使用和在Java中使用java.security.MessageDige st。这个实验没有比较完全相同的逻辑而是表明P HP扩展的使用与Ja va即时编译竞争如图2所示。
尽管实验结果显示纯脚本的三个数量级在J ava和P HP上实现更少的性能差异订单但是PHP的扩展使用用C语言编写和编译Ja va类库的变化表现出很大的不同。在极端情况下正常的表达式测试显示Java和P HP之间最高的性能差异大约为5分钟在另一方面 Java和PHP在MD5测试结果中几乎相等。因此一个例如PHP等脚本语言解释的固有性能风险是可以利用高效率的库函数来克服的如使用C语言编写的P HP扩展。
7
指导老师批阅手写
签名
8
npidc全称No Problem Network Co.,Limited(冇問題(香港)科技有限公司,今年4月注册的)正在搞云服务器和独立服务器促销,数据中心有香港、美国、韩国,走CN2+BGP线路无视高峰堵塞,而且不限制流量,支持自定义内存、CPU、硬盘、带宽等,采用金盾+天机+傲盾防御系统拦截CC攻击,非常适合建站等用途。活动链接:https://www.npidc.com/act.html...
Bluehost怎么样,Bluehost好不好,Bluehost成立十八周年全场虚拟主机优惠促销活动开始,购买12个月赠送主流域名和SSL证书,Bluehost是老牌虚拟主机商家了,有需要虚拟主机的朋友赶紧入手吧,活动时间:美国MST时间7月6日中午12:00到8月13日晚上11:59。Bluehost成立于2003年,主营WordPress托管、虚拟主机、VPS主机、专用服务器业务。Blueho...
ParkInHost主机商是首次介绍到的主机商,这个商家是2013年的印度主机商,隶属于印度DiggDigital公司,主营业务有俄罗斯、荷兰、德国等机房的抗投诉虚拟主机、VPS主机和独立服务器。也看到商家的数据中心还有中国香港和美国、法国等,不过香港机房肯定不是直连的。根据曾经对于抗投诉外贸主机的了解,虽然ParkInHost以无视DMCA的抗投诉VPS和抗投诉服务器,但是,我们还是要做好数据备...