《PHP和JSP作为服务器脚本语言的性能比较-毕业论文外文翻译.doc》由会员分享,可在线阅读,更多相关《PHP和JSP作为服务器脚本语言的性能比较-毕业论文外文翻译.doc(7页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、Performance Comparison of PHP and JSP as Server-Side Scripting LanguagesMaterialSource: Notesin Computer Science Author: Scott Trent; Michiaki Tatsubori; Toyotaro Suzumura; Akihiko Tozawa and Tamiya Onodera1 IntroductionThe dynamic scripting language PHP(PHP Hypertext Preprocessor) has become enormo
2、usly popular for implementing lightweight web applications,and is widely used to access databases and other middleware.Apache module popularity surveys performed by Security Space in October 2007 indicate that 37% of Apache servers have PHP support enabled ,making it the most popular Apache module b
3、y 10 percentage points.Businesses are quickly realizing the powerful combination of a service oriented architecture environment with dynamic scripting languages like PHP .However,we believe that there are still critical performance issues involving PHP which remain to be investigated.This paper focu
4、ses on the use of dynamic scripting languages to implement web server front-end interfaces. This corresponds with the way that the industry standard web server performance benchmark SPECweb2005 utilizes PHP and JSP ( JavaServer Pages).In this case, scripts are used for the implementation of dynamic
5、page generation, rather than the realization of complex business logic. This contrasts with the traditional uses of complex JSP-based business logic implementation.While there are numerous studies on dynamic web content, this paper complements these studies with detailed analysis focusing on PHP. Fo
6、r example, following the performance study on CGI (Common Gateway Interface) based web servers for dynamic content by Yeager & McGrath back in 1995, researchers and practitioners have been examining the performance of more recent dynamic Webcontent generation technologies. These works, however, hand
7、le application scenarios where servlet front-ends implement relatively complex business logic. Although Warner and Worley discuss the importance of also using PHP with SPECweb2005, to the best of the authors knowledge, this paper is the first to publish a detailed analysis of SPECweb2005 experimenta
8、l results using both PHP and JSP. The detailed analysis of PHP and JSP performance based on SPECweb2005 offered by this paper enables designers and implementers of web servers to understand the relative performance and through put of different versions and configurations of PHP and JSP.2 Multi-tier
9、Web Server Architecture: Lightweight Front-End Using PHP/JSP Developers typically use PHP to implement a front-end interface to dynamic Web content generators, which are combined with web server software and back-end servers to provide dynamic content. The web server directly handles requests for st
10、atic content and forwards requests for dynamic content to the dynamic content generator. The dynamic content generator, supported by back-end servers, executes code which realizes the business logic of a web site and stores dynamic state. Back-end servers may be implemented as a straight-forward dat
11、abase, or may be more complex servers handling the business logic of the web site. The front-end implementation may vary from heavy-weight business logic handlers to lightweight clients composing content received from back-end servers. This paper focuses on multi-tier web site development scenarios
12、utilizing such lightweight front-ends, supported by one or more layers of heavy-weight back-ends. This assumption is reasonable when considering Service-Oriented environments where PHP scripts are used to implement a mash-up of services provided elsewhere, in addition to the case of simple web sites
13、 such as bulletin boards where PHP scripts are just a wrapper to a database. Within the scenarios described in this paper, the dynamic content generator provides client implementation in addition to page composition. It connects to the back-end server through a network using either standard protocol
14、s such as HTTP or application/middleware-specific protocols.JSP technology can be considered an alternative to PHP in implementing such front-ends. While it is part of the Java Servlet framework, developers typically use JSP to implement lightweight front-ends. Both PHP and JSP allow developers to w
15、rite HTML embedded code. In fact, although there are language inherent differences between PHP and Java, 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 of lightweight front-end dynamic content generation
16、 written in PHP and JSP with popular web servers such as Apache and Lighttpd. This web server architecture scenario involves users who access a web server with pages written in plain static HTML, as well as JSP and PHP scripts which mix scripting language with HTML code. The configuration assumed wi
17、thin the paper is a typical one, where web server software, such as Apache, distinguishes between pure HTML, JSP, and PHP respectively with suffixes such as .html, .jsp, and .php. HTML code is directly returned to the requesting end-users web browser, where JSP and PHP pages are respectively parsed
18、by the Tomcat script engine and the PHP runtime engine which both provide pure HTML which is forwarded to the end-user on a remote system. A common point between JSP and PHP is that implementations which perform well have a dynamically compiled and cached byte code. For example, the Java runtime use
19、d by the Tomcat script engine which we used performs much better when the Just-in-Time (JIT) compiler is enabled to create efficient cached native runtime code. Similarly, the Zend PHP runtime we used also performs significantly better when the Alternative PHP Cache (APC) is enabled, in which APC st
20、ores PHP byte codes compiled from the script source code in shared memory for future reuse.3 Language Runtime Performance Micro BenchmarkingTo understand the difference in performance characteristics between PHP and Java at the language runtime level,we compared the following engines using a series
21、of micro benchmark tests:- 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) compilation (same as above)The PHP language framework allows developers to extend the language with library functions written in C. These func
22、tions, which are known as extensions, are then available to be used within PHP scripts. The PHP runtime provides a variety of extensions for string manipulation, file handling, networking, and so forth. Since our first goal was to understand the performance of the PHP runtime itself, we conducted ou
23、r experiments without the use of extensions. We developed the following micro benchmarks: - A quick sort benchmark which sorts 100 integers, - A Levenshtein benchmark which measures the similarity between two strings of 56 characters, -A Fibonacci benchmark which calculates the 15th value in a Fibon
24、acci series with two arbitrary starting values.These PHP benchmarks were implemented entirely with PHP language primitives and avoided the use of PHP extensions. The Java versions also focused on using language primitives rather than standard classes. We compared the total run time of executing each
25、 test 10,000 times with each engine. We also executed each benchmark an additional 10,000 times as a warm-up, before the measured test. This prevents Java just-in-time compilation overhead from impacting the score in the Java tests. We ran the experiment on an Intel Pentium 4 CPU at 3.40 GHz with 3G
26、B RAM Memory, with the Linux 2.6.17 kernel. This test demonstrates large performance differences between each of themeasured scripting languages and implementations. The experimental results in Figure 1 indicate that “Java 5 with JIT compilation” performs the best, followed “Java 5 without JIT compi
27、lation”, “PHP 5.2.3”, and “PHP 4.4.7” in all measured cases. Java 5 with JIT demonstrated nearly three orders of magnitude better performance due to the use of efficiently generated native code. It is also obvious that PHP 5.2.3 has a two to three times performance improvement over PHP 4.4.7 with th
28、e measured computations. Secondly to determine the performance effect of PHP extensions compared with Java class methods, we developed and tested three additional micro benchmarks: regular expression matching, MD5 encoding, and Levenshtein comparison. For regular expression matching, the Perl Compat
29、ible Regular Expression extension (through the preg_match() function) was used in PHP, and the java. util.regex package was used in Java. For MD5 encoding, the MD5 extension was used in PHP and java.security. MessageDigest was used in Java. This experiment does not compare exactly the same logic, bu
30、t rather demonstrates that the use of PHP extensions is competitive with Java using just-in-time compilation, as seen in Figure 2.Although the pure script experiment showed three orders of magnitude difference between the performance of various implementations of Java and PHP, the use of PHP extensi
31、ons (written in C) and compiled Java class libraries show much less variation. In the extreme, the regular expression test showed a maximum performance difference of about five times between Java and PHP, on the other end, the MD5 test results were nearly equivalent between Java and PHP. Thus a inhe
32、rent performance risk of interpreted scripted languages such as PHP can be overcome with the use of efficient library functions such as PHP extensions written in C. 3PHP和JSP作为服务器脚本语言的性能比较资料来源: 计算机科学讲义 作者:Scott Trent;Michiaki Tatsubori;Toyotaro Suzumura;Akihiko Tozawa 和Tamiya Onodera1简介动态脚本语言PHP(PHP超
33、文本预处理器)已经成为非常流行的轻量级Web执行应用程序,并广泛用于访问数据库和其他中间件。2007年10月流行的Apache模块安全空间进行的调查表明,37%的Apache服务器支持PHP功能,以10个百分点使它成为最流行的Apache模块。企业正迅速实现与动态脚本语言,如PHP的面向服务的体系结构环境的强大组合。然而,我们相信仍然有重要的性能问题涉及到PHP,它仍有待于被调查。本文重点介绍了动态脚本语言的使用来实现Web服务器的前端接口。与此对应的方式,该行业标准的Web服务器性能的基准SPECweb2005利用PHP和JSP(JavaServer页面)。在这种情况下,脚本是用于执行动态页
34、面生成,而不是复杂的业务逻辑的实现。与此相反的传统用途是基于JSP的复杂的业务逻辑实现。虽然有许多动态网页内容的研究,本文补充了这些研究的详细分析,重点在于PHP中。例如,下面就CGI(通用网关接口)基于Web服务器的动态内容由耶格尔麦格拉思可追溯到1995年的性能研究,研究人员和从业者一直在研究最近的动态的WebContent技术性能。这些作品,然而,处理应用程序方案在servlet前端实现相对复杂的业务逻辑。虽然华纳和沃利也使用PHP与SPECweb2005,以作者所知的重要性,本文是首次发布了使用PHP和JSP的SPECweb2005实验结果的详细分析。PHP和JSP的性能的详细分析是基
35、于本文件所提供的SPECweb2005,使设计者和实施者了解Web服务器的相对性能,并通过把不同版本的PHP和JSP进行配置。2 多层Web服务器架构:使用PHP/JSP的轻量级前端开发人员通常使用PHP来实现一个生成动态Web内容的前端界面,这与Web服务器软件和后端服务器相结合,提供动态内容。该网站的服务器直接处理静态内容并转发请求动态内容生成动态内容。后端服务器支持动态内容生成,执行代码来实现一个网站和商店的动态状态的业务逻辑。后端服务器可以作为一个直接的数据库来实现,或者可能更复杂的服务器处理该网站的业务逻辑。前端的执行可能有所不同于重量级的业务逻辑程序来处理从后端服务器接收轻量级客户
36、端的内容。本文重点介绍多层Web站点开发利用这种由一个或多个重量级后端层支持轻量级的前端。当考虑到面向服务的环境中PHP脚本用来实现提供其他地方的一个“混搭”的服务,这种假设是合理的。除了简单的网站情况下,例如公告板中PHP脚本只是一个包装到一个数据库。在本文中所描述的场景中,动态内容生成器提供动态内容页组成,除了客户端实现。它通过使用标准协议诸如HTTP或应用程序/中间件特定协议连接到后端服务器。JSP技术可以被认为是对PHP在执行这些前端的一种选择。虽然它是Java Servlet的框架的一部分,开发人员通常使用JSP来实现轻量级前端。PHP和JSP允许开发人员可以编写HTML嵌入代码。事
37、实上,虽然PHP和Java之间有着固有的不同之处,但PHP的脚本和JSP文件在使用上的差异可能会非常相似。在这份文件中详细介绍了实验的目的是衡量结合诸如Apache和Lighttpd的流行Web服务器,使用PHP和JSP编写的轻量级前端动态内容生成器性能。此Web服务器架构方案涉及用户访问使用纯静态页面HTML编写的Web服务器,以及JSP和PHP脚本混合脚本语言和HTML代码。本文内承担的配置是一个典型的,其中Web服务器软件,如Apache,后缀与纯粹的HTML,JSP和PHP等之间的区别分别是.html,.jsp和.php。HTML代码是直接返回到最终用户请求的网络浏览器,在JSP和PH
38、P页面分别由Tomcat的脚本引擎和PHP运行时引擎提供纯HTML转发给最终在远程系统的用户进行解析。JSP和PHP之间的共同点是,这些执行良好的实现有一个动态编译和缓存的字节码。例如,Java运行时使用Tomcat的脚本引擎,当实时(JIT)编译器功能来创建有效的本地缓存的运行时代码时我们执行越好。同样,我们使用了Zend的PHP运行时当可替代的PHP缓存(APC)启用,则执行明显好,从共享内存中APC存储PHP字节码,以便将来重用脚本源代码。3 语言运行时性能微标杆为了了解PHP语言运行时水平在性能特点上的不同,我们比较了用微型基准测试一下引擎:-PHP的4.4.7-PHP的5.2.3-J
39、ava 5与实时(JIT)编译(IBM的J9虚拟机1.5.0 Build 2.3)-Java 5 不只是实时(JIT)编译(同上)PHP语言框架允许开发人员扩展这些用C语言编写的功能,这些功能被称为“扩展”,称为库函数的语言,然后提供给PHP脚本内使用。PHP运行时提供了多种扩展的字符串操作,文件处理,网络等等。由于我们的首要目标是了解PHP运行时本身的性能,我们实施的实验没有使用扩展。我们制定了以下微基准:-以100个整数进行快速排序的基准-一个Levenshtein基准检测两行56个字符的字符串的相似性-一个斐波纳契计算基准,在一个任意两个初始值斐波纳契数列第15的值。这些PHP的基准完全
40、用PHP原始语言实现和避免了PHP扩展的使用。Java的版本也侧重于利用原始的语言而不是标准类的语言。我们比较了每个引擎执行每个测试10000次的总运行时间。每个测试前我们也执行作为热身的额外10000次测量基准。这可以防止在Java影响得分的测试中即时编译。我们在3.40GB的RAM内存,4CPU的Intel奔腾与Linux2.6.17内核上运行实验。此测试演示测量之间的脚本语言和实现的巨大性能差异。图1中的实验结果表明,“JIT编译的Java 5”性能最好,在所有测量案件中“没有JIT编译的Java 5”,“PHP的5.2.3”,“PHP的4.4.7”次之。Java 5基于有效地生成本地代
41、码使用,结合JIT演示了近三个数量级更好性能的订单。显而易见的是,PHP的5.2.3有两倍至三倍的性能改进超过实际测量计算的PHP的4.4.7。其次,以PHP与Java类的方法相比确定扩展性能的影响,我们开发和测试三种额外的微基准:常规的表达式匹配,MD5编码和Levenshtein比较。对于常规表达式匹配,Perl兼容常规表达式扩展(通过preg_match()函数)使用PHP和在Java中使用java.util.regex包。对于MD5编码,MD5的扩展也在PHP中使用和在Java中使用java.security.MessageDigest。这个实验没有比较完全相同的逻辑,而是表明PHP扩展的使用与Java即时编译竞争,如图2所示。尽管实验结果显示纯脚本的三个数量级在Java和PHP上实现更少的性能差异订单,但是PHP的扩展使用(用C语言编写)和编译Java类库的变化表现出很大的不同。在极端情况下,正常的表达式测试显示Java和PHP之间最高的性能差异大约为5分钟,在另一方面,Java和PHP在MD5测试结果中几乎相等。因此,一个例如PHP等脚本语言解释的固有性能风险是可以利用高效率的库函数来克服的,如使用C语言编写的PHP扩展。