Optimizing Web Application`s Execution Time By Caching PHP

Transcription

Optimizing Web Application`s Execution Time By Caching PHP
2015 International Conference on Computer Science and Information Systems (ICCSIS-15) April 24-25, 2015 Pattaya (Thailand)
Optimizing Web Application’s Execution Time
By Caching PHP ByteCode Using Zend OPCache
R. Olalia Jr., A. Bugayong, and R. Eden
Abstract—In this paper, the researchers tested several factors
that could affect a PHP web applications execution time such as
web browsers, presence of anti-virus or anti-malware, operating
system, versions of PHP, MySQL and Apache and the absence of
PHP optimizer. Necessary computer has been configured and set-up
to simulate stated scenario. This paper also discussed how caching
PHP bytecode will greatly increase web application’s execution
time.
II. BACKGROUND
During the development of the Student Information
Management System (SIMS) by the MIS department of San
Carlos College, specifically in preparation of collection report
by the accounting department, it is noted the PHP web
application generated a collection report for 122 seconds at
the server itself. Although the process displays accurate result,
the execution time is somewhat unacceptable. According to
the report by Amy Gesenhues [1], the average web page load
time is 7.25 seconds.
The collection report composes of 56 lines of PHP codes
with three nested iterations (while statement) and 4 nested
selection statements, accessing a total of, by the time of
testing, 39,712 records from 3 different tables but within a
single database. The actual number of records that were
processed was calculated by inserting a simple PHP code on
the existing web app (the collection report) that will sum the
records.
The web application is running on a computer with an Intel
i3 3.10 GHz (Quad Core) Processor, 2 Gb RAM, and 2 TB of
HDD. The computer was installed with MySQL Community
Server 5.6.12, Apache 2.4.4, PHP 5.4.16 and Windows 8
operating system. The said server is connected through a
ProLink H5004n router (with 4 ethernet ports and 1 WAN
port) and a 16-Port TP-Link (10/100Mbps) desktop switch.
Index Terms—caching bytecode, optimizing web application,
web application execution time, zend opcache.
I. INTRODUCTION
Normally, after a web application has been setup and tested
to be running, it will be left until something unusual was
discovered like the slow execution time and too much delay.
That is one of the loopholes most developer go into during the
phase of their development and maintenance.
This scenario is especially true when developing web
applications that stores and retrieves record from a relational
database system. Added to this is the compatibility issues of
web browsers, the server’s operating system, presence of antivirus and firewall, versions of PHP and Apache, and absence
of PHP optimizer.
This research focused on how to optimize the execution
time of a PHP web applications by testing known and possible
factors that may affect the throughput of the application. The
hypothesis is that the researchers believe that one or more
factors directly affect the speed of the execution and thus after
series of testing the researchers can come up with
configuration and settings that will fully optimize web
application’s execution time.
As a disclaimer, this research was conducted based on the
scenario experienced by the researchers with their Student
Information Management System (SIMS) for San Carlos
College and therefore will not represent all web applications.
Test result may vary from one application to another.
III. FINDINGS
As investigation furthers on, some assumptions on the
factors affecting the execution time were drawn. Since it can
be agreed that an increase in hardware performance will make
the execution time even faster, the researchers disregarded it
because an upgrade in server hardware is not instant and
cheap. It is not also a good idea to just keep on upgrading
hardware components to speed up execution time but the
application is still not optimize.
Table I shows factors that could affect, directly or
indirectly, the web applications execution time.
TABLE 1
FACTORS THAT MIGHT AFFECT EXECUTION TIME
Factors that could affect execution time
1. Web Browsers
2. Presence of anti-virus / anti-malware
3. Version of Apache, MySQL and PHP
4. Operating System
5. Absence of PHP optimizer
R. Olalia Jr., Head of the MIS department and a faculty member of the
College of Information and Computing Studies
A. Bugayong, Technical Assistant at the MIS Department of San Carlos
College and a faculty member of College of Information and Computing
Studies at San Carlos College, Pangasinan
R. Eden, Dean of the College of Information and Computing Studies and
concurrently, as Head of Quality Assurance and Standards Office of San
Carlos College, San Carlos City, Pangasinan.
http://dx.doi.org/10.15242/IAE.IAE0415015
35
2015 International Conference on Computer Science and Information Systems (ICCSIS-15) April 24-25, 2015 Pattaya (Thailand)
To be able for the researchers validate the hypothesis, they
have set up the same PHP web application to run in the
original server computer (as stated in the background).
It can be concluded based on Table 4 that upgrade on the
version of PHP, Apache and MySQL does not contributed
much on the execution speed. It only lessen the execution
time by 1 second on both browser.
A. Web Browsers
D. Operating System
To narrow the testing, the web application was tested on 4
major web browsers to test if the choice of browser affects the
execution time. The following table (Table II) show the
execution time of each browser.
Since Windows 8 is not the most appropriate operating
system for a server [3] because of its memory limitation on
x86 systems compare to Ubuntu[4], the researchers loaded a
live Linux Debian variant (Ubuntu 14.04 LTS Trusty Thar)
into the same computer through a bootable 8GB flash drive.
The web application was migrated on top of the Linux OS
utilizing the upgraded Apache, MySQL and PHP. Table V
shows the result of the test.
TABLE II
EXECUTION TIME FOR EACH WEB BROWSERS.
Browser
Execution Time
Firefox (Developer)
124 seconds
Chrome
123 seconds
Opera
122 seconds
Internet Explorer
125 seconds
TABLE V
EXECUTION TIME FOR OPERA AND INTERNET EXPLORER FOR THE WEB
APPLICATION RUNNING ON UBUNTU LINUX.
Browser
Execution Time
Opera
51 seconds
Internet Explorer
52 seconds
Based on the result, all browsers have very little difference
on the execution. Although Opera is a bit faster by 3 seconds
compare to Firefox and Internet Explorer, the difference
between these browsers cannot compensate the problem.
After noting that Opera executes the fastest and Internet
Explorer the slowest, these two browsers was used to get the
execution range of web application.
Surprisingly, web application running on a Linux operating
system is faster than the original operating system. Execution
time was increased by 58% on both Opera and Internet
Explorer compare to the original recording. This criterion is a
major milestone to the study and a major decision factor that
may affect the MIS Department in migrating their web
application to Ubuntu Linux.
B. Presence of anti-virus / anti-malware
The next factor that might affect the execution is the
presence of any anti-virus and/or anti-malware software.
These were disabled and tests are conducted again. Table III
shows the result.
E. Absence of PHP Optimize
According to article by David Shafik,[5] PHP is a scripting
language which is compiled every time it is executed. Fig. 1
shows the compilation life cycle of PHP.
TABLE III
EXECUTION TIME FOR OPERA AND INTERNET EXPLORER WITH ANTIVIRUS
AND ANTIMALWARE DISABLED.
Browser
Execution Time
Opera
118 seconds
Internet Explorer
120 seconds
With antivirus and antimalware disabled, Internet Explorer
lessens execution time by 4% and Opera by 3.3%. Although
time was lessen, anti-virus and anti-malware should not be
disabled for security purpose. Therefore, antivirus and antimalware were re-enabled on the succeeding tests.
C. PHP Version
PHP has been updated regularly. Up to this writing, latest
version of PHP is 5.6. With lots of addition and optimization
involve in every version, updating the server’s PHP might
help speed up web application’s execution time. From PHP
5.4 the server was updated to PHP 5.5.
Zend Technologies has opened their product OPCache
(formerly known as Zend Optimizer) and has been bundled
with PHP distribution starting version 5.5 but by default is
disabled.[2] Apache was also upgraded from version 2.4.4 to
2.4.7 and MySQL from version 5.6.12 to 5.6.23. The
following tests were conducted with OPCache disabled.
Table IV shows the execution time for Opera and Internet
Explorer after the upgrade. (Note that the anti-virus and antimalware is enabled again.)
Fig. 1 The PHP Compilation Life Cycle
A PHP Optimizer works by storing OpCodes (compiled
PHP code) into the cache. There are two scenarios during the
execution while PHP optimizer is loaded. The first run will be
as usual as if no optimizer is loaded and second run will be
the optimized since a compiled version of the code is now
present.[6] Fig. 2 shows the whole process.
TABLE IV
EXECUTION TIME FOR OPERA AND INTERNET EXPLORER UTILIZING PHP 5.5.
Browser
Execution Time
Opera
120 seconds
Internet Explorer
124 seconds
http://dx.doi.org/10.15242/IAE.IAE0415015
36
2015 International Conference on Computer Science and Information Systems (ICCSIS-15) April 24-25, 2015 Pattaya (Thailand)
department of San Carlos College. Appropriate test are
conducted setting each scenario in a controlled environment.
While some other factors didn’t affect much of the execution
time, the choice of operating system and proper configuration
and utilization of PHP optimizer did the job expected. It is
therefore recommended by the researchers that a bold move to
migrate the web application stated in the background of the
study be done and Zend OPCache be implemented to solve
the aforementioned problem.
ACKNOWLEDGMENT
Authors would like to thank the administration of San
Carlos College for supporting our research financially and for
the encouragement bestowed during the conduct of the
research. To our relatives and love ones who continue to
believe in us and pray for the success of the research. To God
be the glory!
REFERENCES
[1]
Fig. 2 The PHP Compilation Life Cycle with OPCache
To test, OPCache was enabled once again and will be run
twice, recording the difference between the execution time.
Browser’s history are erased to make sure browsers cache will
not be loaded during the test. A great leap of speed was
recorded as shown in Table VI.
[2]
[3]
TABLE VI
EXECUTION TIME FOR OPERA AND INTERNET EXPLORER FOR THE WEB
APPLICATION RUNNING ON UBUNTU LINUX WITH OPCACHE IMPLEMENTED.
Browser
Execution Time
Execution Time
(1st run)
(2ndrun)
Opera
51 seconds
4 seconds
Internet
Explorer
52 seconds
4 seconds
[4]
[5]
[6]
The first execution recorded the same with the result with
no OPCache enabled (refer to Table V). This is because
according to figure 2 when no OPCache was detected by the
optimizer, normal life cycle of the execution will be done.
However, after the second execution, both Opera and IE
generated the needed report for only 4 seconds. That is 96.7%
less in execution time for Opera and 96.8% for Internet
Explorer.
Romulo L. Olalia Jr. was born at Bautista, Pangasinan,
Philippines on September 17, 1981. He graduated BS
Computer Science in 2004 at Lyceum-Northwestern
University in Dagupan City, Philippines and recently
earned his Master in Information Technology in 2013
at Colegio de Dagupan, Dagupan City, Philippines.
He is currently working as the Head of the MIS department and a faculty
member of the College of Information and Computing Studies at San Carlos
College, Pangasinan.
Mr. Olalia has published an article in the institutional level and in an
international journal.
IV. CONCLUSION
While it can be noted that several factors might affect a
web applications execution time, the most noted criteria are
the change in operating system and the utilization of Zend
OPCache.
However, the researchers didn’t conduct a comprehensive
test on the different operating systems with regards to using it
as a server for web application. There is also no comparison
on the optimization capability of other PHP optimizer aside
from what comes from Zend which is OPCache.
This study was initiated with a problem in mind which was
personally encountered by the researchers in the MIS
http://dx.doi.org/10.15242/IAE.IAE0415015
Gesenhues, A. (March 2013). Top Retail Websites Not Getting Faster:
Average Web Page Load Time is 7.25 Seconds. [Online] Available:
http://marketingland.
com/retail-website-load-times-continue-to-decline-with-a-22-decreaseduring-the-last-year-37604
Fidoloper. (2013). Speed up you PHP application with Zend OPCache.
[Online] Available: http://fideloper.com/install-zend-opcache
Microsoft. (2015). Memory limits for Windows and \ Windows Server
Releases.
[Online]
Available:
https://msdn.microsoft.com/enus/library/windows/desktop/aa366778%28v=vs.85%29.aspx#physical
_memory_limits_windows_8
AskUbuntu. (2011). Does Ubuntu desktop 32bit support more than
4GB of Memory with Default Installation. [Online] Available:
http://askubuntu.com/questions/20049/does-ubuntu-desktop-32bitsupport-more-than-4gb-memory-with-default-installation
Shafik, D. (2013). PHP Performnce I: Everything you need to know
about OPCode Cache. [Online] Available:
https://support.cloud.engineyard.com/entries/26902267-PHPPerformance-I-Everything-You-Need-to-Know-About-OpCodeCaches
StackOverflow. C2014. OPCache – understanding how the cache orks.
Retrieved at http://stackoverflow.com/questions/20329035/opcacheunderstanding-how-the-cache-works-per-user-or-per-resource
Alfie V. Bugayong was born in San Carlos City,
Pangasinan, Philippines on June 2, 1990. He graduated
BS Computer Science in 2010 at Binalatongan
Community College, San Carlos City, Philippines. He
earned his Master in Information Technology in 2013 at
Colegio de Dagupan, Dagupan City, Philippines.
He is currently working as Technical Assistant at the MIS Department of
San Carlos College and a faculty member of College of Information and
Computing Studies of the same institution.
Mr. Bugayong has published an article in the institutional level and in an
international journal.
37
2015 International Conference on Computer Science and Information Systems (ICCSIS-15) April 24-25, 2015 Pattaya (Thailand)
Roldan B. Eden was born at Mangaldan, Pangasinan,
Philippines on Jne 12, 1975. He graduated BS
Computer Science in 1997 at Asiacareer College,
Dagupan City, Philippines. He earned his Master of
Science in Information Technology in 2007 at Saint
Louis University, Baguio City, Philippines and
completed his academic requiremends for his doctoral
degree in Information Technology at Technological Institute of the
Philippines, Quezon City, Philippines.
He is currently working as Dean of the College of Information and
Computing Studies and concurrently, as Head of Quality Assurance and
Standards Office of San Carlos College, San Carlos City, Pangasinan.
Mr. Eden has published an article in the institutional level in the area of
data mining.
http://dx.doi.org/10.15242/IAE.IAE0415015
38