Tune Web servers
Monitor IHS and Apache
Monitor...
- CPU utilization
- IHS error_log
- IHS http_plugin.log
Threads
Edit http.conf to ensure that enough threads are available for the maximum number of concurrent client connections.
Check the IHS error_log file to see if there are any warnings about having reached the maximum number of clients (MaxClients).
Support thousands of concurrent clients
It is not unusual for a single IHS system to support thousands of concurrent clients. If the requirements are to support more concurrent clients than the number of threads that are supported by the Web server operating system and hardware, consider using multiple Web servers.
Respond to a Connection Refused error message
To mitigate Connection Refused error messages after an increase in the number of clients. Increase...
- ListenBacklog
Maximum allowed number of pending connections.
The IHS default is 511, but the actual value can be much higher or lower depending on the corresponding OS parameter.
- StartServers
Number of IHS processes to initially start. Pre-starting these IHS threads reduces the chance of a user having to wait for a new process to start. Set to a value equal to MinSpareServers.
Prevent the frequent creation and destruction of client processes as the number of users change
Use MinSpareServers and MaxSpareServers to specify the minimum and maximum number of servers (client threads/processes) that can exist in an idle state. To prevent frequent creation and destruction of client processes as the number of users change, set this range large enough to include the maximum number of simultaneous users.
Change the setting on the Web server's Access logging parameter
If we do not need to log every access to the appserver, change the default value of the Web server's Access logging parameter. This change will reduce the load on the Web server.
Modify Load balancing option and Retry interval plug-in properties
Load balancing option The load balancing option is used by the plug-in to send requests to appservers associated with the Web server. The default option is Round Robin, which provides an even distribution of work across cluster members. Round Robin works best with Web servers that have a single process sending requests to the appserver. If the Web server is using multiple processes to send requests to the appserver, the Random option can sometimes yield a more even distribution of work across the cluster.
Retry interval Length of time to wait before trying to connect to a server that has been marked temporarily unavailable. The plug-in marks a server temporarily unavailable if the connection to the server fails. Although a default value is 60 seconds, we might have to lower this value in order to increase throughput under heavy load conditions. Lowering the RetryInterval might help when the IHS is configured to have fewer than 10 threads per process.
How can lowering the RetryInterval affect throughput? If the plug-in attempts to connect to a particular application server while the appserver threads are busy handling other connections, which happens under heavy load conditions, the connection might time out, causing the plug-in to mark the server temporarily unavailable. If the same plug-in process has other connections open to the same server and a response is received on one of these connections, the server is marked again. If there are only a few threads per IHS process, there might not be an established connection to this appserver . When this situation occurs, the plug-in must wait for the entire retry interval.
Although lowering the RetryInterval can improve performance, if all the appservers are running, a low value can have an adverse affect when one of the application servers is down. In this case, each IHS process attempts to connect and fail more frequently, resulting in increased latency and decreased overall throughput.
To modify these properties, in the admin console, go to...
Servers | Server Types | Web Servers | web_server_name | Plug-in properties | Request routing
Apache vs. Yaws
Apache dies after 4000 concurrent connections, while Yaws handles at least 85000. This is why Facebook could not use Apache for their chat implementation (they use Erlang/C++).
Parallel connections and browser choice
The Http 1.1 specification says that a browser should allow at the most two parallel connections per host name. If a web page has 20 resources the browser will start 2 downloads and queue the rest. Once a download is finished it will start next download from queue
The number of parallel connections depends on browser...
IE v6 and v7 2 IE v8 6 Firefox v2 2 Firefox v3 6 Safari v3 and v4 4 Opera 4 Chrome 4 Ways to mitigate this issue...
- Use multiple web hosts to download resources. For example, use one host to download HTML and other hosts to download images and css.
- Combine files of similar type...
- Use tools like Dojo Shrink Safe, YUI Compressor to combine multiple JS files
- Create a custom Dojo Build with additional classes, widgets,.. etc
- Use YUI Compressor to combine multiple .css files
- Use Images Maps, CSS Sprites
- Inline smaller, non-cacheable resources
Parallel connections and javascript
When a browser encounters a <script> tag in html, it will stop everything until it downloads, parses, and executes the script.Script tags with a document.write(), will cause the browser to wait.
Scripts performing long executing onload operations also have problems.
Scripts on page must be executed in proper order. For example, second.js might depend on first.js, so first.js must be executed before second.js.
Some of the newer browsers download scripts in parallel but execute them in order.
Expiry based caching
As of HTTP 1.1 you can set response header to cache for a number of seconds. For example...
Cache-Control: max-age=<noofseconds>
With HTTP 1.0 you can set response header to cache the resource until a certain date. For example...
Expires: Fri, 1 Oct 2010 12:00:00 GMT(Date in GMT)
To set both Cache-control and Expires headers, enable the mod_expires module and configure attributes. For example, the following sets images to be cached for 3 months, and other resources to be cached for 1 month.
ExpiresActive On
ExpiresDefault "access 1 month"
ExpiresByType image/gif "access plus 3 month"If you set both Cache-Control and Expires header then Cache-Control will take precedence.
Cache-Control sesources will be purged from cache if the browser's cache size is reached.
If you don't know when resource will be updated, configure sites so that HTML never gets cached and other resources get cached for long time (Months or years)
HTML document has references to all the resources on the page, so if a resource is changed, change its reference/URL in the HTML.
- Change the file name Ex. From test.js to test_v1.js
- Change the folder Ex test.js to v1/test.js
- Create mod_rewrite rule. Ex v1/test.js, v2/test.js, v3/test.js gets mapped to test.js
If you know precisely when resource will be updated set Expires to that date
Configure caching of resources served by WebSphere
The file serving servlet, used for serving static files, does not set the expires/cache-control header.
You can set Expires/Cache-Control headers in Servlets by editing navigatorservice.properties For portlets, set expiration-cache and cache-scope in portlet.xml.
Use ResourceResponse.getCacheControl() to get object of javax.portlet.CacheControl and call its method setExpirationTime() and setPublicScope() methods
Use ResourceURL.setCacheability() so that WPS generates cache friendly URLs
Use gzip for compressing response
Compressing resources with GZip will reduce the size of resource by 70 %
Most modern browsers support compressed data. Browser sends Accept-Encoding header to specify what all encodings it supports
You can configure HTTP server to compress both static files that it serves and dynamic content that goes through it
You should compress only text files such as HTML, JavaScript, CSS
You should not compress binary files such as Images, PDF, They are already compressed and there size might increase after GZip
You should not compress resources less than 150 bytes
How to configure apache http server for gzip
Apache HTTP Server has a mod_deflate module that you can use to GZip the response
You can use it to GZip both static files served by Apache and dynamic responses that are tunneled through Apache HTTP Server
- It checks if browser supports GZip and if yes then only GZip.s response
- It allows you to configure GZip by content type
LoadModule deflate_module modules/mod_deflate.so
AddOutputFilterByType DEFLATE text/html text/plain text/xml- Set Vary: Accept-Encoding so the proxy can deal with clients who do not support GZip properly
Minify text files
Minification is the practice of removing unnecessary characters from the code to reduce its size
- Extra spaces
- Line breaks
- Indentation
- Comments
You can use tools to minify
- JavaScript
- CSS
- HTML
Minify JavaScript
Compacting JavaScript code can save many bytes of data and speed up downloading, parsing, and execution time.
Minification will reduce size by up to 30 %
There are several tools that you can use for minifying JavaScript
- Dojo Shrink safe
- YUI Compressor
- Google's Closure compiler
Task to minify JavaScript should be part of your build script. You can also minify JavaScript on the fly using Servlet Filter
Minify css
Compacting CSS code can save many bytes of data and speed up downloading, parsing, and execution time.
Minifying CSS has same advantages that of minifying JavaScript Tools for minifying CSS...
- YUI Compressor
- Cssmin.js
You can add task to minify CSS in the build script. You can minify CSS on the fly using Servlet Filter.
Minify HTML
There are YUI Tag libraries that you can use to compress inline JavaScript and CSS
WebSphere generates quite few blank lines and white spaces in HTML
Set property...
com.ibm.wsspi.jsp.usecdatatrim
...to true in Web Container Custom settings to bring size of generated HTML by up to 15%
Optimize images
Images saved from programs like Fireworks can contain kilobytes of extra comments, and use too many colors, even though a reduction in the color palette may not perceptibly reduce image quality
Choose an appropriate Image file format
- PNGs are almost always superior to GIFs and are usually the best choice
- Use GIFs for very small or simple graphics and for images which contain animation.
- Use JPGs for all photographic-style images.
- Do not use BMPs or TIFFs.
Use an image compressor
Optimize browser rendering
Once resources have been downloaded to the client, the browser still needs to load, interpret, and render HTML, CSS, and Javascript code. By simply formatting your code and pages in ways that exploit the characteristics of current browsers, you can enhance performance on the client side.
- Put CSS at the top of the document
- Always specify content type encoding
- Specifying a character set early for your HTML documents allows the browser to begin executing scripts immediately
- Put JavaScript at the end of the document
- Avoid CSS expressions
Capture browser performance data
Load testing tools that run inside browser...
- iOpus iMacros
- Selenium
- Gomez
- Yahoo YSlow
- Google Page speed
- Charles Web Debugging Proxy
Reduce dns resolution time
Before a browser establishes a connection with server it must resolve host name into IP address. This value is cached by
- Operating System
- Browser
The DNS record cache has short life time and might have to traverse hierarchy to get record
Reducing the number of unique hostnames from which resources are served cuts down on the number of DNS resolutions that the browser has to make
Don't use more than 1 host for less than 5 resources, balance resources across host names
Serve early loaded JavaScript from same domain as that of host
Browsers block parallel download while downloading JavaScript, so it should be as fast as possible
Caching Proxies
Proxies are everywhere on the network:
- ISP proxies
- Corporate network proxies for outbound connection
- Inbound connection proxies for web servers
Enable public caching in the HTTP headers for static resources allows the browser to download resources from a nearby proxy server rather than from a remoter origin server
You use the Cache-control: public header to indicate that a resource can be cached by public web proxies in addition to the browser that issued the request.
Set appropriate Vary header (Vary: Accept-Encoding, User-Agent)
Consider disabling ETag
ETags are introduced to help with multiple HTTP server environment
HTTP Server can generate ETag(Similar to a version number) for the static resources. Its enabled by default. The default format of ETag is INode MTime Size
Apache HTTP Server sends both Last-Modified and ETag header. You cant disable Last-Modified. Browser will send both If-Modified-Since and If-None-Match header to check if resource is still valid As per HTTP Specification both IMS and INM conditions should be met for server to return HTTP 304 (Desired behavior with smaller response)
If your request goes to HTTP server that has different file permission but same date, Server will return HTTP 200 instead of HTTP 304
You can configure, disable ETag by adding FileETag None to httpd.conf. Or at least configure it to FileETag MTime
Validation based caching
When a static HTML file is served (Apache HTTP Server, WebSphere.s File Serving Servlet), the server will send Last-Modified header will value equal to date when the file was modified (OS date)
Apache HTTP Server can generate ETag for static files based on its modification time, size,..
If you don.t set Cache-Control: no-store, browser will store the response in cache
But every time you request the resource(No cached, or stale) it will send Conditional GET request, with If-Modified-Since, If-None-Match header
Server will check if the resource is actually modified, if not it will return HTTP 304 with no body(Average 250 byte response) to indicate that browser can use the response
Validation based caching is better than getting full HTTP 200 response with full body but worst than cached resource which does not require HTTP request
Size of http request
Most users have asymmetric connection, upload to download speed is in ration 1:4 to 1:20. That means uploading 500 bytes is same as downloading 10 KB. We cant compress data in HTTP request. You should try and keep your request size small so that it fits in one packet of 1500 bytes
Initial HTTP request suffers from Startup Throttling
HTTP request is made up of following things
- Request header set by browser
- URL, Referral URL
- Cookies
You should try and reduce size of each of the request components
Reduce cookie size
Enterprise applications often require at least a few big cookies to be sent in request from from browser...
- LTPA Token
- JSessionId
- SSO related cookies
Every time a client sends an HTTP request, it has to send all associated cookies that have been set for that domain and path along with it.
Use server side storage for cookie for most of the cookie payload and send only a Key in the cookie.
- Serving static resources from a cookie less domain reduces the total size of requests made for a page
- Static resources do not need cookies
Typical static file will be less than 10 KB, so more time is spent in making request then getting response
Cache validation
The HTTP Specification has concept of Conditional GET, that helps client to prevent download of same resource repeatedly
The Server can send Last-Modified, ETag header in response
HTTP Client (Browser, caching proxies) will copy the resource in disk cache along with the headers
Next time when you request that resource the client will add If-Modified-Since and If-None-Match headers to the request with the value that it had on disk
Server compares this values to the version it has and sends a HTTP 200 OK, with full resource in the body of response if the resource is changed but if the resource is not changed the server will send HTTP 304 Not Modified with only headers
- Original resource could be say 100kb, but the HTTP 304 respose will be 200-250 bytes, you can save on download size
- Client has to make a request using one of the connections from parallel connection pool
For more information, see:
http://wpcertification.blogspot.com/search/label/clientsideperformance
Configure the IHS to show a status page
- Edit IHS httpd.conf and remove the comments from...
#LoadModule status_module, modules/ApacheModuleStatus.dll, #<Location/server-status>
#SetHandler server-status
#</Location>- Save the changes and restart the IHS.
- Go to...
http://yourhost/server-statusClick Reload to update status.
If the browser supports refresh, go to...
http://my_host/server-status?refresh=5...to refresh every five seconds.
Related tasks
Communicate with Web servers
Tune the application serving environment
Web server plug-in tuning tips