Performance Tuning PHP on IBM i
Transcript of Performance Tuning PHP on IBM i
© All rights reserved. Zend Technologies, Inc.
Performance Tuning PHP on IBM i
Mike Pavlak
Solution Consultant
Alan Seiden
Strategic Business Systems
Watch the recorded webinar: http://bit.ly/A4NjYM
© All rights reserved. Zend Technologies, Inc.
Agenda
•What affects performance
•Zend Server configuration
•Review hardware architecture
•Explore Web specific opportunities
•Where to get additional help
•Wrap up
•Q&A
2
© All rights reserved. Zend Technologies, Inc.
Performance is in the eye of the beholder…
Perception is reality
Many pieces to the performance puzzle
Rarely a single silver bullet
Performance tuning is a journey, not a destination
Learn as you go
Commercial websites look great…
• And can be great motivators for change
PHP is often accused but rarely convicted
3
© All rights reserved. Zend Technologies, Inc.
Major contributors to performance issues
•Additive workload
•Transitional workload
•Organic growth
•Network infrastructure
•Entropy
•A piece of advice…
When you see these coming…GET IN FRONT OF THEM
• Or get run over!
4 Insert->Header & Footer
© All rights reserved. Zend Technologies, Inc.
Speed = money
•Google’s experiment
Google Search lists 10 results per page
They tested pages of 30 results
• Traffic and revenue dropped by 20%
• Why?
– 10 results took .4 seconds to generate
– 30 results took .9 seconds
• A ½ second delay caused a 20% drop in traffic
Source:
http://glinden.blogspot.com/2006/11/marissa
-mayer-at-web-20.html
Performance Tuning PHP on IBM i | 5
© All rights reserved. Zend Technologies, Inc.
Speed = competitiveness
•Search engine ranking
Since early 2010, Google’s search algorithm has included speed
Faster sites rank higher, all else being equal
•Consumers lose patience with slow sites
With many choices, users give up on sites that drag
Patience has decreased since the 1990s
•Slower sites often waste bandwidth and CPU
Costly infrastructure driven by performance mistakes
Performance Tuning PHP on IBM i | 6
© All rights reserved. Zend Technologies, Inc.
How do we improve performance
•Subject of this webinar
Doing what you are doing now!
•From the softer side
Communication with other teams is essential
• While it is encouraged to bang you head against the wall…
• Do not suffer in silence, reach out for help
Education
• If you think education is expensive, try ignorance!
Services
• There are folks who may know more than you. Hire them.
7 Insert->Header & Footer
© All rights reserved. Zend Technologies, Inc.
Performance Tuning PHP on IBM i
www.zend.com
Looking at Zend Server Administration
© All rights reserved. Zend Technologies, Inc.
Zend Server for IBM i 5.6
•Zend Server is Home Base
•Configuration options abound
•We will look at
FastCGI settings
Logs
Extensions
9 Insert->Header & Footer
© All rights reserved. Zend Technologies, Inc.
Fast CGI
•Mechanism for communicating between Apache and PHP
•Built in with 10 server jobs at the time of installation
•This should conform to concurrent processes
•Watch this as more workload is migrated to web
10 Insert->Header & Footer
© All rights reserved. Zend Technologies, Inc.
Fast CGI
•Changing this
is something that should be considered
But not taken lightly (system resources, etc.)
•File to edit:
/www/zendsvr/conf/fastcgi.conf
SetEnv="PHP_FCGI_CHILDREN=10"
•But don’t forget…
StartProcesses = “2” * PHP_FCGI_CHILDREN = 8 is 16 total worker jobs
http://www.youngiprofessionals.com/wiki/FastCGI
http://www.systeminetwork.com/article/other-
languages/fastcgi-boosts-php-performance-on-ibm-i-66195
11 Insert->Header & Footer
© All rights reserved. Zend Technologies, Inc.
PHP Logs
• IFS performance, minimize read/writes
Alan will discuss more
But what about the logs
•Consider the event monitor
•Read the logs
•Reduce the messages
•Clip the log
/usr/local/zendsvr/var/log/php.log
12 Insert->Header & Footer
© All rights reserved. Zend Technologies, Inc.
Rename the log
•Zend Server will create more!
REN OBJ('/usr/local/zendsvr/var/log/php.log') NEWOBJ(phplog20120306.txt)
13 Insert->Header & Footer
© All rights reserved. Zend Technologies, Inc.
Extensions
•PHP travels with a posse
70+ extensions
Many are used every day
But if not used, may be turned off…
Default,
• Zend Server for IBM i shipped with DB2 on and SQL Server off
• Look at the Zend Server admin interface
– Server setup Extensions
– Like a light switch
14 Insert->Header & Footer
© All rights reserved. Zend Technologies, Inc.
IBM i administration
•PTF’s
Current cumulative & group for HTTP
•Memory pools
Isolate memory from other attacks
•Workload partitioning
With i6.1 & i7.1 can protect processor without LPAR
•Understanding demands on the systems
If the boss doesn’t believe you, have your BP back you up!
Performance Monitor tools
3rd party
15 Insert->Header & Footer
© All rights reserved. Zend Technologies, Inc.
WRKSYSSTS – The first place to go!!!
16 Insert->Header & Footer
© All rights reserved. Zend Technologies, Inc.
Performance Tuning PHP on IBM i
www.zend.com
Tools
© All rights reserved. Zend Technologies, Inc.
Firebug add-on graphs performance
•Firebug
https://addons.mozilla.org/firefox/addon/firebug/
Even better with FirePHP and Page Speed
Performance Tuning PHP on IBM i | 18
© All rights reserved. Zend Technologies, Inc.
Performance Tuning PHP on IBM i
www.zend.com
Use Compression
© All rights reserved. Zend Technologies, Inc.
Compression reduces file size
• Called gzip or mod_deflate (the same for our purposes)
• Compresses, speeds up html, javascript, css, any text
• Add two lines (OK, two long lines) to httpd.conf Apache config
LoadModule deflate_module
/QSYS.LIB/QHTTPSVR.LIB/QZSRCORE.SRVPGM
AddOutputFilterByType DEFLATE application/x-httpd-php
application/json text/css application/x-javascript
application/javascript text/html
Performance Tuning PHP on IBM i | 20
© All rights reserved. Zend Technologies, Inc.
Netflix saw improvement with gzip/deflate
•Saw 13-25% performance improvement
•Cut outbound traffic in half
That saves money for a busy site such as Netflix
•Details of Netflix improvement:
http://www.slideshare.net/billwscott/improving-netflix-
performance-experience
• It really works!
•Tutorial on my blog:
http://www.alanseiden.com/2010/08/13/maximize-zend-
server-performance-with-apache-compression/
Performance Tuning PHP on IBM i | 21
© All rights reserved. Zend Technologies, Inc.
Performance Tuning PHP on IBM i
www.zend.com
Reduce HTTP Requests
© All rights reserved. Zend Technologies, Inc.
Requests cause “blocking” in browser
•Browsers typically limit themselves to 2 parallel requests to
a given server
•File requests stack up, blocked by prev. requests
•
Performance Tuning PHP on IBM i | 23
• Above, even “not modified” files caused blocking
• Solution: reduce number of images or improve
caching via “Expires” headers
http://httpd.apache.org/docs/2.0/mod/mod_expires.html
© All rights reserved. Zend Technologies, Inc.
More ways to reduce “blocking”
• If many .js or .css files are used:
Combine them into fewer files
Move contents of smaller .js or .css files inline to your pages,
eliminating those external files
Page Speed tool will help you decide
Performance Tuning PHP on IBM i | 24
© All rights reserved. Zend Technologies, Inc.
Performance Tuning PHP on IBM i
www.zend.com
Ajax: friend or foe?
© All rights reserved. Zend Technologies, Inc.
AJAX=Asynchronous Javascript And XML
•AJAX updates parts of a page without reloading the whole
page
•Not always XML. These days, JSON too
•Requests and file sizes are generally small
•Meant to bring SPEED to the web
•Potential problems if overused
Performance Tuning PHP on IBM i | 26
© All rights reserved. Zend Technologies, Inc.
AJAX mistake #1
•Too much of a good thing
Requiring several AJAX requests to complete before the page itself can load fully
Too many HTTP requests at once
I’ve seen a situation where 4 AJAX requests were embedded in a page load
• The AJAX doesn’t even start till the page loads
• Causes “blocking” as the requests pile up, waiting for the previous ones to complete
Solution: when page first loads, embed AJAX content right in the page
• Re-use logic on the server side when building page
• Subsequent updates can be done with AJAX
Performance Tuning PHP on IBM i | 27
© All rights reserved. Zend Technologies, Inc.
AJAX mistake #2
•Duplicate requests
Might go unnoticed with javascript library tools (Dojo, jQuery...)
Happens more than you would expect! Common, actually
Performance Tuning PHP on IBM i | 28
© All rights reserved. Zend Technologies, Inc.
AJAX mistake #3
• Dynamically generating static content (don’t do that)
• Solutions:
Change to static files
Cache URLs (e.g. with Zend Data Cache if using PHP, or Apache caching)
See example below, before and after caching
Performance Tuning PHP on IBM i | 29
© All rights reserved. Zend Technologies, Inc.
Performance Tuning PHP on IBM i
www.zend.com
Keep-alive
© All rights reserved. Zend Technologies, Inc.
Keep HTTP connections alive • “Keep-alive” setting in Apache (or any web server)
• The HTTP job will stay open, waiting for you
Perfect when downloading many images, css, js files
• Configurable by number of seconds to keep connection open,
number of files to be downloaded
KeepAlive On
KeepAliveTimeout 15
See http://httpd.apache.org/docs/2.0/mod/core.html#keepalive
• Don’t overdo it—you are locking out other users from that HTTP
job while it’s dedicated to you
Performance Tuning PHP on IBM i | 31
© All rights reserved. Zend Technologies, Inc.
Connecting takes time
•Clues that Keepalive is off
“Connection: close”, “Connecting”
•Example bottom right: 3.6 seconds “Connecting” (longer
than average but it really happened)
Performance Tuning PHP on IBM i | 32
© All rights reserved. Zend Technologies, Inc.
What you see when Keep-alive is on
•Firebug’s “Net” tab shows “Connection: Keep-Alive”, and,
here, timeout=300 seconds (5 minutes)
Performance Tuning PHP on IBM i | 33
• Zero seconds to
connect
• Keep-alive is working!
© All rights reserved. Zend Technologies, Inc.
Performance Tuning PHP on IBM i
www.zend.com
Persistent DB Connections
© All rights reserved. Zend Technologies, Inc.
Persistence = connection pool
•On IBM i, job initialization is relatively slow
Gives us good things—auditing, logging, security
Solution: a pool of pre-initialized jobs
•Pre-started DB2 jobs save time
Generally run in subsystem QSYSWRK, job name QSQSRVR
These prestart jobs can be configured with CHGPJE command
• In PHP, persistent connections reuse initialized jobs
db2_pconnect()
Dramatic speed boost
Performance Tuning PHP on IBM i | 35
© All rights reserved. Zend Technologies, Inc.
Use db2_pconnect() to connect persistently
•resource db2_pconnect ( string $database , string
$username , string $password [, array $options ] )
•Persistent is much faster than non-persistent
db2_pconnect can reuse connections, reducing the time needed
to connect (after the first time) to almost zero
•How db2_pconnect() reuses connections
Connections defined by database, username, and password
Tries to reuse an existing connection matching these 3 params
db2_close() on a persistent connection does nothing
db2_pclose() forces the conn to close
Performance Tuning PHP on IBM i | 36
© All rights reserved. Zend Technologies, Inc.
db2_pconnect() example with library list
$database = 'MYDB';
$user = 'MYUSER';
$password = 'MYPASS';
// set library list (works the same for connect or pconnect)
$options = array('i5_naming' => DB2_I5_NAMING_ON,
'i5_libl' => 'MYLIB1 MYLIB2');
$conn = db2_pconnect($database, $user, $password, $options);
if ($conn) {
echo "Connection succeeded.";
} else {
echo "Connection failed.";
}
// MYTABLE will be found, if in library MYLIB1 or MYLIB2
$stmt=db2_exec($conn,"SELECT * FROM MYTABLE");
Performance Tuning PHP on IBM i | 37
© All rights reserved. Zend Technologies, Inc.
Rules for using persistence
•Because connections are shared when defined with an
identical database, user, and password, please:
Avoid unpredictable results by also specifying the same $options
for these connections
Promote sharing of jobs by minimizing the number of user profiles
that you connect with
• Each user profile creates a new set of database jobs
• Each set of jobs consumes system resources
•More information:
“DB2 and PHP Best Practices on IBM i” at
http://alanseiden.com/presentations
Performance Tuning PHP on IBM i | 38
© All rights reserved. Zend Technologies, Inc.
New open source PHP IBM i toolkit • Ships with Zend Server 5.6+
PTFs and hotfixes on download page
Many improvements since first release
• Information and updates:
Young i Professionals site
• http://youngiprofessionals.com/wiki/XMLSERVICE
Zend Forum for Q&A and tips
• http://forums.zend.com/viewtopic.php?f=113&t=41648
• “PHP on IBM i”->”Zend Server for IBM i”->”New Toolkit”
• Efficient: use single DB2 connection for SQL and Toolkit
http://forums.zend.com/viewtopic.php?f=113&t=46688
Persistent connection is the fastest
Performance Tuning PHP on IBM i | 39
© All rights reserved. Zend Technologies, Inc.
Performance Tuning PHP on IBM i
www.zend.com
Wrap it up
© All rights reserved. Zend Technologies, Inc.
Help!
• I’ve got PHP applications and not sure what to do?
•Do your homework
Read, learn, explore
Talk in forums (Zend.com and midrange.com)
•Zend Services
Application Audit
• Up to 50,000 lines of code
• Review on site or off (knowledge transfer!)
• Report summary & remediation available
41 Insert->Header & Footer
© All rights reserved. Zend Technologies, Inc.
Zend Performance Audit
42 Zend Professional Services
Comprehensive Methodology
Detailed evaluation of your application and environment
Detailed analysis of performance patterns and behaviors
Provide report and improvements recommendations
Proven Success
Delivered to numerous Global 1000 companies
Accelerated performance across industries
Methodologies applied to hundreds of applications
Delivered by the PHP Company Experts
Unparalleled experience in PHP and Zend Server
Methodology developed by the architects of PHP
Utilizing Zend standard benchmarks
© All rights reserved. Zend Technologies, Inc.
Zend Server features (Full version)
•Event Monitor
Become aware of issues before your users call
•Code Tracing
Black box flight recorder for PHP scripts
•Caching
Op-code (Alan discussed & available with CE)
Data (Also available with CE)
Page
•Job Queue
SBMJOB for PHP!!!
43 Insert->Header & Footer
© All rights reserved. Zend Technologies, Inc.
Webcasts
•April 12 – Stored Procedures Part II (RPG, etc.)
•May 2 – Additional Functions of DB2 with PHP on IBM i
Your thoughts???
44 Insert->Header & Footer
© All rights reserved. Zend Technologies, Inc.
Events where you’ll find Zend…
45 Insert->Header & Footer
•User groups
WMCPA (Lake Geneva, WI) Mar 20-22 (Mike & Alan)
• http://wmcpa.org/
NEUGC (Boston, MA) April 2-4
• http://neugc.org/
Alan:
March 29: COMMON webcast: more performance tips http://www.common.org/index.php/webcasts/upcoming-webcasts.html
April 5: live online event with System i Network New PHP Toolkit for IBM i http://www.systeminetwork.com/events/upcoming-events
In New York City? I host the NYC Zend Framework Meetup http://www.meetup.com/ZendFramework-NYCmetro/
© All rights reserved. Zend Technologies, Inc.
Events where you’ll find Zend…(cont.)
46 Insert->Header & Footer
•Major venues
RPG & DB2 Summit (Ft. Worth, TX) Mar 25-28
• http://www.systemideveloper.com/Summit/conferences.html
COMMON Annual Meeting and Expo (Anaheim, CA) May 6-9
• http://www.common.org/index.php/annualmeeting.html
COMMON Fall Conference (Columbus, OH) Sep 24-26
• http://www.common.org/index.php/fall-conference-and-expo.html
© All rights reserved. Zend Technologies, Inc.
Contact | Get tips
Performance Tuning PHP on IBM i | 47
Free PHP/i tips by email:
http://alanseiden.com/tips
Alan Seiden Strategic Business Systems, Inc,
201-327-9400 17 S. Franklin Tpk
[email protected] Ramsey, NJ, 07446
http://alanseiden.com Twitter: @alanseiden
© All rights reserved. Zend Technologies, Inc. 48
Q&A
Watch the recorded webinar: http://bit.ly/A4NjYM