| Sun ONE Application Server 7 Performance Tuning Guide |
Chapter 4
Tuning Sun ONE Application ServerThis chapter describes some ways to tune the Sun ONE Application Server for optimum performance. It is separated into the following sections:
HTTP Server TuningMonitoring and tuning the HTTP server instances that handle client requests are important parts of ensuring peak Sun ONE Application Server performance. This section covers the following topics related to HTTP Server Tuning:
Enabling Statistics with stats-xml
Users must enable statistics with stats-xml when they wish to use existing monitoring tools like perfdump or create similar customized tools.
To enable the statistics using stats-xml, follow these steps:
- Under the default object in obj.conf, add the following line:
NameTrans fn="assign-name" from="/stats-xml/*" name="stats-xml"
- Add the following Service function to obj.conf:
<Object name="stats-xml">
Service fn="stats-xml"
</Object>The following figure shows a sample init.conf which has stats-init Server Application Function (SAF) included.
Figure 4-1 statsxml-obj in <instancename>-obj.conf
- Add the stats-init Server Application Function (SAF) to init.conf
The above example shows you can also designate the following:
- update-interval. The period in seconds between statistics updates. A higher setting (less frequent) will be better for performance. The minimum value is 1; the default value is 5.
- virtual-servers. The maximum number of virtual servers for which you track statistics. This number should be set equal to or higher than the number of virtual servers configured. Smaller numbers result in lower memory usage. The minimum value is 1; the default is 1000.
- profiling. Enable NSAPI performance profiling. The default is "no" which results in slightly better server performance.
For more information on editing the configuration files, see the Sun ONE Application Server NSAPI Programmer's Guide.
Monitoring Current Activity Using the perfdump Utility
The perfdump utility is an SAF built into Sun ONE Application Server. It collects various pieces of performance data from the Application Server internal statistics and displays them in ASCII text. The perfdump utility allows you to monitor a greater variety of statistics.
Installing the perfdump Utility
The following figure provides a sample of the <instancename>-obj.conf file with the perfdump utility configured.
Figure 4-3 Sample <instance-name>-obj.conf file with perfdump Configured
To install perfdump, you need to make the following modifications in <instancename>-obj.conf file:
- Add the following object to your <instancename>-obj.conf file after the default object:
<Object name="perf">
Service fn="service-dump"
</Object>- Add the following to the default object:
NameTrans fn=assign-name from="/.perf" name="perf"
- If not already enabled, enable stats-xml.
If you need to enable stats-xml, see “Enabling Statistics with stats-xml”.
- Restart your server software.
- Access perfdump by entering this URL:
http://yourhost/.perf
- You can request the perfdump statistics and specify how frequently (in seconds) the browser should automatically refresh. This example sets the refresh to every 5 seconds:
http://yourhost/.perf?refresh=5
The following figure shows a sample perfdump output.
Figure 4-4 Sample perfdump Output
For more information on editing the configuration files, see the Sun ONE Application Server Developer’s Guide to NSAPI.
Using Statistics to Tune Your Server
This section describes the information available through the perfdump utility and discusses how to tune some parameters to improve your server's performance. The default tuning parameters are appropriate for all sites except those with very high volume. The only parameters that large sites may regularly need to change are RqThrottle, MaxKeepAliveConnections, and KeepAliveTimeout, which can be tuned by using the web-based Administration interface or by directly editing the <instancename>-obj.conf file. The following figure shows the Administration interface for tuning the HTTP Server.
Figure 4-5 Performance Tuning the Server using the Administration Interface
The perfdump utility monitors statistics in the following categories:
Connection Queue Information
Connection queue information shows the number of sessions in the queue, and the average delay before the connection is accepted.
Following is an example of how these statistics are displayed in perfdump:
ConnectionQueue:
---------------------------------
Current/peak/limit queue length 0/48/5000
Total connections queued 3753
Average queueing delay 0.0013 seconds
Current /peak /limit
Current/peak/limit queue length shows, in order:
Tuning
If the peak queue length is close to the limit, you may wish to increase the maximum connection queue size to avoid dropping connections under heavy load.
You can increase the connection queue size by:
- Setting or changing the value of ConnQueueSize from the web-based Administration interface. Follow the path http-server-Advanced-performance.
- Editing the ConnQueueSize directive in init.conf.
Total Connections Queued
Total connections queued is the total number of times a connection has been queued. This includes newly accepted connections and connections from the keep-alive system.
This is a gathered statistic and is not tunable.
Average Queuing Delay
Average queueing delay is the average amount of time a connection spends in the connection queue. This represents the delay between when a request connection is accepted by the server, and a request processing thread (also known as a session) begins servicing the request.
This is a gathered statistic and is not tunable.
HTTP Listener Information
The HTTP listener information includes the IP address, port number, number of acceptor threads, and the default virtual server for the HTTP listener. For tuning purposes, the most important field in the HTTP listener information is the number of acceptor threads.
You can have many listeners enabled for virtual servers, but you will at least have one (usually http://0.0.0.0:80) enabled for your default server instance.
Http listeners1:
------------------------
Address http://0.0.0.0:1890
Acceptor threads 1
Default virtual server test
Tuning
You can create and configure HTTP listeners through the web-based Administration interface. For more information, see Sun ONE Application Server Administration Guide.
If you have created multiple HTTP Listeners, perfdump displays them all.
Set the TCP/IP listen queue size for all HTTP Listeners by:
Address
This field contains the base address that this listener is listening on. It contains the IP address and the port number.
If your HTTP listener listens on all IP addresses for the machine, the IP part of the address is 0.0.0.0.
Tuning
This setting is tunable when you edit a listen socket. If you specify an IP address other than 0.0.0.0, the server will make one less system call per connection. Specify an IP address other than 0.0.0.0 for the best possible performance.
The following figure shows the Administration interface for the HTTP Listener.
Figure 4-6 Tuning the HTTP Listener using the Administration Interface
Acceptor Threads
Acceptor threads are threads that wait for connections. The threads accept connections and put them in a queue where they are then picked up by worker threads. Ideally, you want to have enough acceptor threads so that there is always one available when a user needs one, but few enough so that they do not put too much of a burden on the system. A good rule is to have one acceptor thread per CPU on your system. You can increase this value to about double the number of CPUs if you find indications of TCP/IP listen queue overruns.
Tuning
You can tune the number of acceptor threads by selecting the HTTP listener node and changing the number of acceptor threads on the right hand side of the Advanced category.
The following figure shows the Administration interface for the acceptor threads.
Figure 4-7 Tuning the Acceptor Threads using the Administration Interface
Default Virtual Server
Software virtual servers work using the HTTP 1.1 Host header. If the end user's browser does not send the host header, or if the server cannot find the virtual server specified by the Host header, Sun ONE Application Server handles the request using a default virtual server. Also, for hardware virtual servers, if the application server cannot find the virtual server corresponding to the IP address, it displays the default virtual server. You can configure the default virtual server to send an error message or serve pages from a special document root.
Tuning
You can specify a default virtual server for an individual listen socket and the server instance. If a given HTTP listener does not have a default virtual server, the server instance's default virtual server is used.
You can specify a default virtual server for a listen socket using the web-based Administration interface. You can set or change the default virtual server information using the Edit HTTP Listener page on the Preferences Tab of the web-based Administration interface for the HTTP server. The settings for the default virtual server are on the Connection Group Settings page that appears when you click Groups.
Keep-Alive/Persistent Connection Information
This section provides statistics about the server's HTTP-level keep-alive system.
The following example shows the keep-alive statistics displayed by perfdump:
KeepAliveInfo:
--------------------
KeepAliveCount 1/256
KeepAliveHits 4
KeepAliveFlushes 1
KeepAliveTimeout 30 seconds
Both HTTP 1.0 and HTTP 1.1 support the ability to send multiple requests across a single HTTP session. A web server can receive hundreds of new HTTP requests per second. If every request was allowed to keep the connection open indefinitely, the server could become overloaded with connections. On Unix/Linux systems, this could easily lead to a file table overflow.
To deal with this problem, the server maintains a "Maximum number of ‘waiting’ keep-alive connections" counter. A ‘waiting’ keep-alive connection has fully completed processing the previous request, and is waiting for a new request to arrive on the same connection. If the server has more than the maximum waiting connections open when a new connection waits for a keep-alive request, the server closes the oldest connection. This algorithm keeps an upper bound on the number of open waiting keep-alive connections that the server can maintain.
Sun ONE Application Server does not always honor a keep-alive request from a client. The following conditions cause the server to close a connection even if the client has requested a keep-alive connection:
- KeepAliveTimeout is set to 0.
- MaxKeepAliveConnections count is exceeded.
- Dynamic content, such as a CGI, does not have an HTTP content-length header set. This applies only to HTTP 1.0 requests. If the request is HTTP 1.1, the server honors keep-alive requests even if the content-length is not set. The server can use chuncked encoding for these requests if the client can handle them (indicated by the request header transfer-encoding:chunked). For more information regarding chuncked encoding, see the Sun ONE Application Server Developer’s Guide to NSAPI.
- Request is not HTTP GET or HEAD.
- The request was determined to be bad. For example, if the client sends only headers with no content.
KeepAliveThreads
You can configure the number of threads used in the keep-alive system by:
KeepAliveCount
This setting has two numbers:
Tuning
You can tune the maximum number of sessions the server allows to wait at one time before closing the oldest connection by:
KeepAliveHits
The number of times a request was successfully received from a connection that had been kept alive.
This setting is not tunable.
KeepAliveFlushes
The number of times the server had to close a connection because the KeepAliveCount exceeded the MaxKeepAliveConnections.
This setting is not tunable.
KeepAliveTimeout
Specifies the number of seconds the server allows a client connection to remain open with no activity. A web client may keep a connection to the server open so that multiple requests to one server can be serviced by a single network connection. Since a given server can handle a finite number of open connections, a high number of open connections will prevent new clients from connecting.
Tuning
You can change KeepAliveTimeout by:
KeepAliveQueryMeanTime
This parameter determines the intervals between the polling of Connections being handled by the KeepAlive Subsytem. If this parameter is set to a value N milliseconds, the Response time seen by a client which has requested persistent connections will have an overhead ranging from 0 to N milliseconds. This value is set by default to 1 millisecond (if unspecified in init.conf). This value works well if you expect a concurrent load of no more than about 300 KeepAlive connections. The default value can severely affect the scalability with higher concurrent loads. It is suggested that this be appropriately increased for higher connection load.
Tuning
You can change KeepAliveQueryMeanTime by editing the KeepAliveQueryMeanTime parameter in init.conf.
UseNativePoll
For Unix /Linux users, this parameter should be enabled for maximum performance.
To enable native poll for your keep-alive system from the web-based Administration interface, follow these steps:
- Select the HTTPServer node for the server instance that needs to have this option turned on.
- Select the Advanced Tab on the right hand side of the pane.
- Select the Keep alive page tab.
- Use the drop-down list to set UseNativePoll to ON.
- Click OK.
- Select the server instance tab from the tree view.
- Select Apply Changes.
- Restart the instance to cause your changes to take effect.
The following figure shows how to configure the keep-alive subsystem.
Figure 4-8 Tuning the Keep-Alive/Persistent Connections using the Administration Interface
Session Creation Information
Session creation statistics are only displayed in perfdump. Following is an example of SessionCreationInfo displayed in perfdump:
SessionCreationInfo:
------------------------
Active Sessions 1
Total Sessions Created 48/512
Active Sessions shows the number of sessions (request processing threads) currently servicing requests.
Total Sessions Created shows both the number of sessions that have been created and the maximum number of sessions allowed.
Reaching the maximum number of configured threads is not necessarily undesirable. It is not necessary to automatically increase the number of threads in the server. Reaching this limit means that the server needed this many threads at peak load. As long as it was able to serve requests in a timely manner, the server is adequately tuned. However, at this point connections will queue up in the connection queue, potentially overflowing it. If you check your perfdump output on a regular basis and notice that total sessions created is often near the RqThrottle maximum, you should consider increasing your thread limits.
Tuning
You can increase your thread limits by:
Cache Information
The Cache information section provides statistics on how your file cache is being used. The file cache caches static content so that the server handles requests for static content quickly.
Following is an example of how the cache statistics are displayed in perfdump:
CacheInfo:
------------------
enabled yes
CacheEntries 5/1024
Hit Ratio 93/190 ( 48.95%)
Maximum age 30
enabled
If the cache is disabled, the rest of this section is not displayed.
Tuning
The cache is enabled by default. You can disable it by:
CacheEntries
The number of current cache entries and the maximum number of cache entries are both displayed. A single cache entry represents a single URI.
Tuning
You can set the maximum number of cached entries by:
Hit Ratio (CacheHits / CacheLookups)
The hit ratio gives you the number of file cache hits versus cache lookups. Numbers approaching 100% indicate the file cache is operating effectively, while numbers approaching 0% could indicate that the file cache is not serving many requests.
This setting is not tunable.
Maximum Age
The maximum age displays the maximum age of a valid cache entry. This parameter controls how long cached information is used after a file has been cached. An entry older than the maximum age is replaced by a new entry for the same file.
Tuning
If your web site's content changes infrequently, you may want to increase this value for improved performance. You can set the maximum age by:
- Entering or changing the value in the Maximum Age field of the File Cache Configuration page in the web-based Admin Console for the HTTP server node and selecting the File Caching Tab.
- Editing the MaxAge parameter in the nsfc.conf file. For more information, see the Sun ONE Application Server Developer’s Guide to NSAPI.
The following figure shows the Administration interface for configuring the file cache system.
Figure 4-9 Tuning the File Cache Information using the Administration Interface
Thread Pools
The following figure shows Administration interface for configuring the thread pools.
Figure 4-10 Tuning the Thread Pools using the Administration Interface
Three types of thread pools can be configured through the web-based Administration interface:
Thread Pools (Unix /Linux only)
Since threads on Unix/Linux are always operating system (OS)-scheduled, as opposed to user-scheduled, Unix/Linux users do not need to use native thread pools. Therefore, this option is not offered in a Unix/Linux user interface. However, you can edit the OS-scheduled thread pools and add new thread pools, if needed, using the web-based Administration interface.
Native Thread Pools (NT only)
On NT, the native thread pool (NativePool) is used internally by the server to execute NSAPI functions that require a native thread for execution.
Native pools:
----------------------------
NativePool:
Idle/Peak/Limit 1/1/128
Work queue length/Peak/Limit 0/0/0
Windows NT users can edit their native thread pool settings using the web-based Administration interface.
Sun ONE Application Server uses NSPR, which is an underlying portability layer providing access to the host OS services. This layer provides abstractions for threads that are not always the same as those for the OS-provided threads. These non-native threads have lower scheduling overhead, so their use improves performance. However, these threads are sensitive to blocking calls to the OS, such as I/O calls. To make it easier to write NSAPI extensions that can make use of blocking calls, the server keeps a pool of threads that safely support blocking calls. This usually means it is a native OS thread. During request processing, any NSAPI function that is not marked as being safe for execution on a non-native thread is scheduled for execution on one of the threads in the native thread pool.
If you have written your own NSAPI plug-ins such as NameTrans, Service, or PathCheck functions, these execute by default on a thread from the native thread pool. If your plug-in makes use of the NSAPI functions for I/O exclusively or does not use the NSAPI I/O functions at all, then it can execute on a non-native thread. For this to happen, the function must be loaded with a NativeThread="no" option, indicating that it does not require a native thread.
To do this, add the following to the "load-modules" Init line in the init.conf file:
Init funcs="pcheck_uri_clean_fixed_init" shlib="C:/Netscape/p186244/P186244.dll" fn="load-modules" NativeThread="no"
The NativeThread flag affects all functions in the funcslist, so if you have more than one function in a library, but only some of them use native threads, use separate Init lines.
Generic Thread Pools (NT only)
On NT, you can set up additional thread pools using the web-based Admin Console. Use thread pools to put a limit on the maximum number of requests answered by a service function at any moment. Additional thread pools are a way to run thread-unsafe plug-ins. By defining a pool with a maximum number of threads set to 1, only one request is allowed into the specified service function.
Idle/Peak/Limit
Idle indicates the number of threads that are currently idle. Peak indicates the peak number in the pool. Limit indicates the maximum number of native threads allowed in the thread pool, and is determined by the setting of NativePoolMaxThreads.
Tuning
You can modify the NativePoolMaxThreads by:
Work Queue Length /Peak /Limit
These numbers refer to a queue of server requests that are waiting for the use of a native thread from the pool. The Work Queue Length is the current number of requests waiting for a native thread.
Peak is the highest number of requests that were ever queued up simultaneously for the use of a native thread since the server was started. This value can be viewed as the maximum concurrency for requests requiring a native thread.
Limit is the maximum number of requests that can be queued at one time to wait for a native thread, and is determined by the setting of NativePoolQueueSize.
Tuning
You can modify the NativePoolQueueSize by:
NativePoolStackSize (NT only)
The NativePoolStackSize determines the stack size in bytes of each thread in the native (kernel) thread pool.
Tuning
You can modify the NativePoolStackSize by:
NativePoolQueueSize (NT only)
The NativePoolQueueSize determines the number of threads that can wait in the queue for the thread pool. If all threads in the pool are busy, the next request-handling thread that needs to use a thread in the native pool must wait in the queue. If the queue is full, the next request-handling thread that tries to get in the queue is rejected, and a busy response is returned to the client. It is then free to handle another incoming request instead of being tied up waiting in the queue.
Setting The NativePoolQueueSize lower than the RqThrottle value causes the server to execute a busy function instead of the intended NSAPI function whenever the number of requests waiting for service by pool threads exceeds this value. The default returns a "503 Service Unavailable" response and logs a message if LogVerbose is enabled. Setting The NativePoolQueueSize higher than RqThrottle causes the server to reject connections before a busy function can execute.
This value represents the maximum number of concurrent requests for service which require a native thread. If your system is unable to fulfill requests due to load, letting more requests queue up increases the latency for requests and could result in all available request threads waiting for a native thread. In general, set this value to be high enough to avoid rejecting requests by anticipating the maximum number of concurrent users who would execute requests requiring a native thread.
The difference between this value and RqThrottle is the number of requests reserved for non-native thread requests, such as static HTML and image files. Keeping a reserve and rejecting requests ensures that your server continues to fill requests for static files, which prevents it from becoming unresponsive during periods of very heavy dynamic content load. If your server consistently rejects connections, this value is either set too low, or your server hardware is overloaded.
Tuning
You can modify the NativePoolQueueSize by:
NativePoolMaxThreads (NT only)
NativePoolMaxThreads determine the maximum number of threads in the native (kernel) thread pool.
A higher value allows more requests to execute concurrently, but has more overhead due to context switching, so "bigger is not always better." Typically, you will not need to increase this number, but if you are not saturating your CPU and you are seeing requests queue up, you should increase this number.
Tuning
You can modify the NativePoolMaxThreads by editing the NativePoolMaxThreads parameter in init.conf.
NativePoolMinThreads (NT only)
Determines the minimum number of threads in the native (kernel) thread pool.
Tuning
You can modify the NativePoolMinThreads by:
DNS Cache Information
The DNS cache caches IP addresses and DNS names. Your server's DNS cache is disabled by default. In the DNS Statistics for Process ID All page under Monitor in the web-based Administration interface the following statistics are displayed:
enabled
If the DNS cache is disabled, the rest of this section is not displayed.
Tuning
By default, the DNS cache is off. You can enable DNS caching by:
CacheEntries (CurrentCacheEntries / MaxCacheEntries)
The number of current cache entries and the maximum number of cache entries. A single cache entry represents a single IP address or DNS name lookup. The cache should be as large as the maximum number of clients that will access your web site concurrently. Note that setting the cache size too high will waste memory and degrade performance.
Tuning
You can set the maximum size of the DNS cache by:
HitRatio (CacheHits / CacheLookups)
The hit ratio displays the number of cache hits versus the number of cache lookups.
This setting is not tunable.
Note
If you turn off DNS lookups on your server, host name restrictions will not work and hostnames will not appear in your log files. Instead, you'll see IP addresses.
Caching DNS Entries
You can also specify whether to cache the DNS entries. If you enable the DNS cache, the server can store hostname information after receiving it. If the server needs information about the client in the future, the information is cached and available without further querying. You can specify the size of the DNS cache and an expiration time for DNS cache entries. The DNS cache can contain 32 to 32768 entries; the default value is 1024. Values for the time it takes for a cache entry to expire can range from 1 second to 1 year specified in seconds; the default value is 1200 seconds (20 minutes).
Limit DNS Lookups to Asynchronous
It is recommended that you do not use DNS lookups in server processes because they are so resource-intensive. If you must include DNS lookups, be sure to make them asynchronous.
enabled
If asynchronous DNS is disabled, the rest of this section will not be displayed.
Tuning
You can enable asynchronous DNS by:
NameLookups
The number of name lookups (DNS name to IP address) that have been done since the server was started.
This setting is not tunable.
AddrLookups
The number of address loops (IP address to DNS name) that have been done since the server was started.
This setting is not tunable.
LookupsInProgress
The current number of lookups in progress.
This setting is not tunable.
The following figure shows the Administration interface for configuring the DNS cache information.
Figure 4-11 Tuning the DNS Cache Information using the Administration Interface
Busy Functions
The default busy function returns a "503 Service Unavailable" response and logs a message if LogVerbose is enabled. You may wish to modify this behavior for your application. To better troubleshoot performance problems, it is useful to specify your own busy functions for any NSAPI function in the <instancename>-obj.conf file by including a service function in the configuration file in this format:
busy="<my-busy-function>"
For example, you could use this sample service function:
Service fn="send-cgi" busy="service-toobusy"
This allows different responses if the server becomes too busy in the course of processing a request that includes a number of types (such as Service, AddLog, and PathCheck). Note that your busy function will apply to all functions that require a native thread to execute when the default thread type is non-native.
To use your own busy function instead of the default busy function for the entire server, you can write an NSAPI init function that includes a func_insert call as shown below:
extern "C" NSAPI_PUBLIC int my_custom_busy_function(pblock *pb, Session *sn, Request *rq);
my_init(pblock *pb, Session *, Request *)
{
func_insert("service-toobusy", my_custom_busy_function);
}
Busy functions are never executed on a pool thread, so you must be careful to avoid using function calls that could cause the thread to block.
Using Performance Buckets
Performance buckets allow you to define buckets, and link them to various server functions. Every time one of these functions is invoked, the server collects statistical data and adds it to the bucket. For example, send-cgi and NSServletService are functions used to serve the CGI and Java servlet requests respectively. You can either define two buckets to maintain separate counters for CGI and servlet requests, or create one bucket that counts requests for both types of dynamic content. The cost of collecting this information is little and impact on the server performance is usually negligible. The following information is stored in a bucket:
- Name of the bucket. This name is used for associating the bucket with a function.
- Description. A description of the functions associated with the bucket.
- Number of requests for this function. The total number of requests that caused this function to be called.
- Number of times the function was invoked. This number may not coincide with the number of requests for the function because some functions may be executed more than once for a single request.
- Function latency or the dispatch time. The time taken by the server to invoke the function.
- Function time. The time spent in the function itself.
The default-bucket is pre-defined by the server. It records statistics for the functions not associated with any user defined bucket.
Configuration
You must specify all the configuration information for performance buckets in the init.conf and <instancename>-obj.conf files. Only the default bucket is automatically enabled.
The following examples show how to define new buckets in init.conf:
Init fn="define-perf-bucket" name="acl-bucket" description="ACL bucket"
Init fn="define-perf-bucket" name="file-bucket" description="Non-cached responses"
Init fn="define-perf-bucket" name="cgi-bucket" description="CGI Stats"
The prior example creates three buckets: acl-bucket, file-bucket, and cgi-bucket. To associate these buckets with functions, add bucket=bucket-name to the obj.conf function for which you wish to measure performance. For example:
PathCheck fn="check-acl" acl="default" bucket="acl-bucket"
...
Service method="(GET|HEAD|POST)" type="*~magnus-internal/*" fn="send-file" bucket="file-bucket"
...
<Object name="cgi">
ObjectType fn="force-type" type="magnus-internal/cgi"
Service fn="send-cgi" bucket="cgi-bucket"
</Object>Performance Report
The performance buckets information is located in the last section of the report that perfdump returns.
For more information, see “Enabling Statistics with stats-xml” and “Using Performance Buckets”.
The report contains the following information:
- Average, Total, and Percent columns give data for each requested statistic.
- Request Processing Time is the total time required by the server to process all the requests it has received so far.
- Number of Requests is the total number of requests for the function.
- Number of Invocations is the total number of times that the function was invoked. This differs from the number of requests in that a function can be called multiple times while processing one request. The percentage column for this row is calculated in reference to the total number of invocations for all the buckets.
- Latency is the time, in seconds, that the Sun ONE Application Server takes to prepare for calling the function.
- Function Processing Time is the time, in seconds, that the Sun ONE Application Server spent inside the function. The percentage of Function Processing Time and Total Response Time is calculated with reference to the total Request processing time.
- Total Response Time is the sum, in seconds, of Function Processing Time and Latency.
The following is an example of the performance bucket information available through perfdump:
Performance Counters:
------------------------------------------------
Average Total Percent
Total number of requests: 474851
Request processing time: 0.0010 485.3198
Default Bucket (default-bucket)
Number of Requests: 597 ( 0.13%)
Number of Invocations: 9554 ( 1.97%)
Latency: 0.0000 0.1526 ( 0.03%)
Function Processing Time: 0.0256 245.0459 ( 50.49%)
Total Response Time: 0.0257 245.1985 ( 50.52%)
Configuring the File Cache
The Sun ONE Application Server uses a file cache to serve static information faster. The file cache contains information about files and static file content. The file cache also caches information that is used to speed up processing of server-parsed HTML.
The file cache is turned on by default. The file cache settings are contained in a file called nsfc.conf. You can use the web-based Administration interface to change the file cache settings.
The following figure shows the Administration interface for configuring the file cache settings.
Figure 4-12 Tuning the File Caching using the Administration Interface
To configure the file cache:
- Select the File Caching tab of the HTTP server.
- Check Enable File Cache, if not already selected.
- Choose whether or not to transmit files.
When you enable Transmit File, the server caches open file descriptors for files in the file cache, rather than the file contents. PR_TransmitFile is used to send the file contents to a client. When Transmit File is enabled, the distinction normally made by the file cache between small, medium, and large files no longer applies since only the open file descriptor is being cached. By default, Transmit File is enabled on NT, and not enabled on Unix. On Unix, enable Transmit File for platforms that have native OS support for PR_TransmitFile, which currently includes HP-UX and AIX. It is not recommended for other Unix/Linux platforms.
- Enter a size for the hash table.
The default size is twice the maximum number of files plus 1. For example, if your maximum number of files is set to 1024, the default hash table size is 2049.
- Enter a maximum age in seconds for a valid cache entry.
By default, this is set to 30.
This setting controls how long cached information will continue to be used once a file has been cached. An entry older than MaxAge is replaced by a new entry for the same file, if the same file is referenced through the cache.
Set the maximum age based on whether the content is updated (existing files are modified) on a regular schedule or not. For example, if content is updated four times a day at regular intervals, you could set the maximum age to 21600 seconds (6 hours). Otherwise, consider setting the maximum age to the longest time you are willing to serve the previous version of a content file after the file has been modified.
- Enter the Maximum Number of Files to be cached.
By default, this is set to 1024.
- (Unix /Linux only) Enter medium and small file size limits in bytes.
By default, the Medium File Size Limit is set to 525000 (525 KB).
By default, Small File Size Limit is set to 2048.
The cache treats small, medium, and large files differently. The contents of medium files are cached by mapping the file into virtual memory (Unix/Linux platforms). The contents of "small" files are cached by allocating heap space and reading the file into it. The contents of "large" files (larger than "medium") are not cached, although information about large files is cached.
The advantage of distinguishing between small files and medium files is to avoid wasting part of many pages of virtual memory when there are lots of small files. So the Small File Size Limit is typically a slightly lower value than the VM page size.
- (Unix /Linux only) Set the medium and small file space.
The medium file space is the size in bytes of the virtual memory used to map all medium sized files. By default, this is set to 10000000 (10MB).
The small file space is the size of heap space in bytes used for the cache, including heap space used to cache small files. By default, this is set to 1MB for Unix/Linux.
- Click OK.
- Click Apply.
- Select Apply Changes to restart your server.
Using the nocache Parameter
You can use the parameter nocache for the Service function send-file to specify that files in a certain directory not be cached. For example, if you have a set of files that changes too rapidly for caching to be useful, you can put them in a directory and instruct the server not to cache files in that directory by editing the <instancename>-obj.conf file.
For example:
<Object name=default>
...
NameTrans fn="pfx2dir" from="/myurl" dir="/export/mydir" name="myname"
...
Service method=(GET|HEAD|POST) type=*~magnus-internal/* fn=send-file
...
</Object>
<Object name="myname">
Service method=(GET|HEAD) type=*~magnus-internal/* fn=send-file nocache=""
</Object>
In the above example, the server does not cache static files from /export/mydir/ when requested by the URL prefix /myurl.
File Cache Dynamic Control and Monitoring
You can add an object to <instancename>-obj.conf to dynamically monitor and control the nsfc.conf file cache while the server is running. To do this:
Add a NameTrans directive to the default object:
NameTrans fn="assign-name" from="/nsfc" name="nsfc"
Add an nsfc object definition:
<Object name="nsfc">
Service fn=service-nsfc-dump
</Object>This enables the file cache control and monitoring function (nsfc-dump) to be accessed via the URI, "/nsfc." By changing the "from" parameter in the NameTrans directive, a different URI can be used.
The following is an example of the information you receive when you access the URI:
Sun ONE Application Server File Cache Status (pid 7960)
The file cache is enabled.
Cache resource utilization
Number of cached file entries = 1039 (112 bytes each, 116368 total bytes)
Heap space used for cache = 237641/1204228 bytes
Mapped memory used for medium file contents = 5742797/10485760 bytes
Number of cache lookup hits = 435877/720427 ( 60.50 %)
Number of hits/misses on cached file info = 212125/128556
Number of hits/misses on cached file content = 19426/502284
Number of outdated cache entries deleted = 0
Number of cache entry replacements = 127405
Total number of cache entries deleted = 127407
Number of busy deleted cache entries = 17
Parameter settings
HitOrder: false
CacheFileInfo: true
CacheFileContent: true
TransmitFile: false
MaxAge: 30 seconds
MaxFiles: 1024 files
SmallFileSizeLimit: 2048 bytes
MediumFileSizeLimit: 537600 bytes
CopyFiles: false
Directory for temporary files: /tmp/netscape/https-axilla.mcom.com
Hash table size: 2049 buckets
You can include a query string when you access the "/nsfc" URI. The following values are recognized:
If you choose the ?list option, the file listing includes the file name, a set of flags, the current number of references to the cache entry, the size of the file, and an internal file ID value. The flags are as follows:
- C - File contents are cached.
- D - Cache entry is marked for delete.
- E - PR_GetFileInfo() returned an error for this file.
- I - File information (size, modify date, etc.) is cached.
- M - File contents are mapped into virtual memory.
- O - File descriptor is cached (when TransmitFile is set to true).
- P - File has associated private data (should appear on shtml files).
- T - Cache entry has a temporary file.
- W - Cache entry is locked for write access.
For sites with scheduled updates to content, consider shutting down the cache while the content is being updated, and starting it again after the update is complete. Although performance will slow down, the server operates normally when the cache is off.
Tuning the ACL User Cache
The ACL user cache is ON by default. Because of the default size of the cache (200 entries), the ACL user cache can be a bottleneck, or can simply not serve its purpose on a site with heavy traffic. On a busy site, more than 200 users can hit ACL-protected resources in less time than the lifetime of the cache entries. When this situation occurs, the Sun ONE Application Server has to query the LDAP server more often to validate users, which impacts performance.
This bottleneck can be avoided by increasing the size of the ACL cache with the ACLUserCacheSize directive in init.conf. Note that increasing the cache size will use more resources; the larger you make the cache the more RAM you'll need to hold it.
There can also be a potential (but much harder to hit) bottleneck with the number of groups stored in a cache entry (by default four). If a user belongs to five groups and hits five ACLs that check for these different groups within the ACL cache lifetime, an additional cache entry is created to hold the additional group entry. When there are two cache entries, the entry with the original group information is ignored.
While it would be extremely unusual to hit this possible performance problem, the number of groups cached in a single ACL cache entry can be tuned with the ACLGroupCacheSize directive.
ACL User Cache Directives
To adjust the ACL user cache values you will need to manually add the following directives to your init.conf file:
ACLCacheLifetime
Set this directive to a number that determines the number of seconds before the cache entries expire. Each time an entry in the cache is referenced, its age is calculated and checked against ACLCacheLifetime. The entry is not used if its age is greater than or equal to the ACLCacheLifetime. The default value is 120 seconds. If this value is set to 0, the cache is turned off. If you use a large number for this value, you may need to restart the Sun ONE Application Server when you make changes to the LDAP entries. For example, if this value is set to 120 seconds, the Sun ONE Application Server might be out of sync with the LDAP server for as long as two minutes. If your LDAP is not likely to change often, use a large number.
ACLUserCacheSize
Set this directive to a number that determines the size of the User Cache (default is 200).
ACLGroupCacheSize
Set this directive to a number that determines how many group IDs can be cached for a single UID/cache entry (default is 4).
Verifying ACL User Cache Settings
With LogVerbose you can verify that the ACL user cache settings are being used. When LogVerbose is running, you should expect to see these messages in your error log when the server starts:
User authentication cache entries expire in ### seconds.
User authentication cache holds ### users.
Up to ### groups are cached for each cached user.
Tuning
You can turn LogVerbose ONby editing the LogVerbose parameter in init.conf.
Caution
Do not turn on LogVerbose on a production server. Doing so degrades performance and increases the size of your error logs.
Using Quality of Service
The quality of service features let you limit the amount of bandwidth and number of connections for a server instance, class of virtual servers, or individual virtual server. You can set these performance limits, track them, and optionally enforce them.
The following figure shows the Administration interface for configuring the Quality of Service.
Figure 4-13 Tuning the Quality of Service using the Administration Interface
For more information, see “Using Quality of Service” in the Sun ONE Application Server Administrator's Guide.
Threads, Processes, and Connections
In the Sun ONE Application Server, acceptor threads on an HTTP Listener accept connections and put them onto a connection queue. Session threads then pick up connections from the queue and service the requests. More session threads are posted if required at the end of the request. The policy for adding new threads is based on the connection queue state:
- Each time a new connection is returned, the number of connections waiting in the queue (the backlog of connections) is compared to the number of session threads already created. If it is greater than the number of threads, more threads are scheduled to be added the next time a request completes.
- The previous backlog is tracked, so that another ThreadIncrement number of threads are scheduled to be added of the following are true:
- The process of adding new session threads is strictly limited by the RqThrottle value.
- To avoid creating too many threads when the backlog increases suddenly (such as the startup of benchmark loads), the decision whether more threads are needed is made only once every 16 or 32 times a connection is made based on how many session threads already exist.
The following directives affect the number and timeout of threads, processes, and connections can be tuned in the web-based Admin Console or init.conf:
For more information about these directives, see the Sun ONE Application Server Developer’s Guide to NSAPI.
HTTP listener Acceptor Threads
You can specify how many threads you want in accept mode on a listen socket at any time. It is a good practice to set this to less than or equal to the number of CPUs in your system.
Tuning
You can set the number of HTTP listener acceptor threads by:
Maximum Simultaneous Requests
The RqThrottle parameter in the init.conf file specifies the maximum number of simultaneous transactions the web server can handle. The default value is 128. Changes to this value can be used to throttle the server, minimizing latencies for the transactions that are performed. The RqThrottle value acts across multiple virtual servers, but does not attempt to load-balance.
To compute the number of simultaneous requests, the server counts the number of active requests, adding one to the number when a new request arrives, subtracting one when it finishes the request. When a new request arrives, the server checks to see if it is already processing the maximum number of requests. If it has reached the limit, it defers processing new requests until the number of active requests drops below the maximum amount.
In theory, you could set the maximum simultaneous requests to 1 and still have a functional server. Setting this value to 1 would mean that the server could only handle one request at a time, but since HTTP requests for static files and generally have a very short duration (response time can be as low as 5 milliseconds), processing one request at a time would still allow you to process up to 200 requests per second.
However, in actuality, Internet clients frequently connect to the server and then do not complete their requests. In these cases, the server waits 30 seconds or more for the data before timing out. You can define this timeout period using the AcceptTimeOut directive in init.conf. The default value is 30 seconds. Also, some sites do heavyweight transactions that take minutes to complete. Both of these factors add to the maximum simultaneous requests that are required. If your site is processing many requests that take many seconds, you may need to increase the number of maximum simultaneous requests. For more information on AcceptTimeOut, see AcceptTimeOut Information.
Suitable RqThrottle values range from 100-500, depending on the load.
RqThrottleMin is the minimum number of threads the server initiates upon start-up. The default value is 48. RqThrottle represents a hard limit for the maximum number of active threads that can run simultaneously, which can become a bottleneck for performance. The default value is 128.
Tuning
You can tune the number of simultaneous requests by:
Improving Java Performance
There are a number of ways you can improve Java performance on Sun ONE Application Server. These include:
Using an Alternate Thread Library
On Solaris 8 and above, using an alternate thread library such as libthread or /usr/lib/lwp, gives optimal performance. This libthread is enabled by default.
Using Pre-compiled JSPs
Compiling JSPs is a resource intensive and time-consuming process. You will improve performance if you pre-compile your JSPs before installing them into your server.
Configuring Class Reloading
The configuration for flag for dynamic reloading should be disabled for better performance. This can be accomplished by editing the server.xml and setting dynamic-reload-enabled="false"
Miscellaneous init.conf Directives
The following sections discuss init.conf directives you can use to configure your server to function more effectively:
AcceptTimeOut Information
Use AcceptTimeOut to specify the number of seconds the server waits between accepting a connection to a client and receiving information from it. The default setting is 30 seconds. Under most circumstances you should not have to change this setting. By setting it to less than the default 30 seconds, you can free up threads sooner. However, you may also disconnect users with slower connections.
Tuning
You can set the AcceptTimeOut by:
CGIStub Processes (Unix/Linux)
You can adjust the CGIStub parameters on Unix/Linux systems. In Sun ONE Application Server, the CGI engine creates CGIStub processes as needed. On systems that serve a large load and rely heavily on CGI-generated content, it is possible for the CGIStub processes to consume all system resources. If this is happening on your server, the CGIStub processes can be tuned to restrict how many new CGIStub processes can be spawned, their timeout value, and the minimum number of CGIStub processes that will be running at any given moment.
Note
If you have an init-cgi function in the init.conf file and you are running in multi-process mode, you must add LateInit = yes to the init-cgi line.
The four directives and their defaults that can be tuned to control CGI stubs are:
MinCGIStubs controls the number of processes that are started by default. The first CGIStub process is not started until a CGI program has been accessed. The default value is 2. If you have an init-cgi directive in the init.conf file, the minimum number of CGIStub processes are spawned at startup.
MaxCGIStubs controls the maximum number of CGIStub processes the server can spawn. This specifies the maximum concurrent CGIStub processes in execution, not the maximum number of pending requests. The default value shown should be adequate for most systems. Setting this too high may actually reduce throughput. The default value is 10.
CGIStubIdleTimeout causes the server to kill any CGIStub processes that have been idle for the number of seconds set by this directive. Once the number of processes is at MinCGIStubs it does not kill any more processes. The default is 45.
CGIExpirationTimeout limits the maximum time in seconds that CGI processes can run.
Tuning
You can configure all of the directives for CGI Stub processes by:
Buffer Size
You can specify the size of the send buffer (SndBufSize) and the receiving buffer (RcvBufSize) at the server's sockets. For more information regarding these buffers, see your Unix/Linux documentation.
Tuning
You can set the buffer size by:
Miscellaneous obj.conf Parameters
You can use some obj.conf function parameters to improve your server's performance. In addition to the ones listed below, see “Using the nocache Parameter” for additional information.
For more information on using obj.conf, see the Sun ONE Application Server Developer’s Guide to NSAPI.
find-pathinfo-forward
The parameter find-pathinfo-forward for the PathCheck function find-pathinfo and the NameTrans functions pfx2dir and assign-name can help you improve your performance. This parameter instructs the server to search forward for PATH_INFO in the path after ntrans-base, instead of backward from the end of path in the server function find-pathinfo.
Note
The server ignores the find-pathinfo-forward parameter if the ntrans-base parameter is not set in rq->vars when the server function find-pathinfo is called. By default, ntrans-base is set.
For example:
NameTrans fn="pfx2dir" find-pathinfo-forward="" from="/cgi-bin" dir="/export/home/cgi-bin" name="cgi"
NameTrans fn="assign-name" from="/perf" find-pathinfo-forward="" name="perf"
This feature can improve performance for certain URLs by doing fewer stats in the server function find-pathinfo. On Windows NT, you can also use this feature to prevent the server from changing "\" to "/" when using the PathCheck server function find-pathinfo.
nostat
You can specify the parameter nostat in the NameTrans function assign-name to prevent the server from doing a stat on a specified URL whenever possible. Use the following syntax:
nostat=virtual-path
For example:
<Object name=default>
NameTrans fn="assign-name" from="/nsfc" nostat="/nsfc" name="nsfc"
</Object>
<Object name=nsfc>
Service fn=service-nsfc-dump
</Object>
In the above example, the server does not stat for path /ntrans-base/nsfc and /ntrans-base/nsfc/* if ntrans-base is set. If ntrans-base is not set, the server does not stat for URLs /nsfc and /nsfc/*. By default ntrans-base is set. The example assumes the default PathCheck server functions are used.
When you use nostat= virtual-path in the assign-nameNameTrans, the server assumes that stat on the specified virtual-path will fail. Therefore, use nostat only when the path of the virtual-path does not exist on the system, for example, in NSAPI plug-in URLs. Using nostat on those URLs improves performance by avoiding unnecessary stats on those URLs.
Scaling Your Server
This section examines subsystems of your server and makes some recommendations for optimal performance:
Processors
On Solaris and Windows NT, Sun ONE Application Server transparently takes advantage of multiple CPUs. In general, the effectiveness of multiple CPUs varies with the operating system and the workload. Dynamic content performance improves as more processors are added to the system. Because static content involves mostly IO, and more primary memory means more caching of the content (assuming the server is tuned to take advantage of the memory) more time is spent in IO rather than any busy CPU activity. Our study of dynamic content performance on a four-CPU machine indicate a 40-60% increase for NSAPI and about 50-80% increase for servlets., by doubling the number of CPUs.
Memory
Sun ONE Application Server requires a minimum of 256 MB RAM on Solaris and Windows. These values apply to the application server running on a system that is not running Sun ONE Studio. Please refer to the Sun ONE Application Server Installation Guide on the Sun Microsystems documentation web site.
Disk Space
You need to have enough disk space for your OS, document tree, and log files. In most cases 2GB total is sufficient.
Put the OS, swap/paging file, Sun ONE Application Server logs, and document tree each on separate hard drives. Thus, if your log files fill up the log drive, your OS will not suffer. Also, you'll be able to tell whether, for example, the OS paging file is causing drive activity.
Your OS vendor may have specific recommendations for how much swap or paging space you should allocate. Based on our testing, Sun ONE Application Server performs best with swap space equal to RAM, plus enough to map the document tree.
Networking
For an Internet site, decide how many peak concurrent users you need the server to handle, and multiply that number of users by the average request size on your site. Your average request may include multiple documents. If you're not sure, try using your home page and all its associated sub-frames and graphics.
Next decide how long the average user will be willing to wait for a document, at peak utilization. Divide by that number of seconds. That's the WAN bandwidth your server needs.
For example, to support a peak of 50 users with an average document size of 24kB, and transferring each document in an average of 5 seconds, we need 240 KBs (1920 kbit/s). So our site needs two T1 lines (each 1544 kbit/s). This also allows some overhead for growth.
Your server's network interface card should support more than the WAN it's connected to. For example, if you have up to three T1 lines, you can get by with a 10BaseT interface. Up to a T3 line (45 Mbit/s), you can use 100BaseT. But if you have more than 50 Mbit/s of WAN bandwidth, consider configuring multiple 100BaseT interfaces, or look at Gigabit Ethernet technology.
For an intranet site, your network is unlikely to be a bottleneck. However, you can use the same calculations as above to decide.
Connection Pool TuningThis section advises how users can tune their JDBC Connection Pools.
For database intensive applications, the JDBC Connection Pools managed by the Sun ONE Application Server can be tuned for optimum performance. These connection pools maintain numerous live physical database connections that can be reused in order reduce the overhead of opening and closing database connections.
JDBC Resources are defined as <jdbc-resource> elements in the Sun ONE Application Server configuration file server.xml and are configured to point to a <jdbc-connection-pool> . J2EE applications use JDBC Resources to obtain connections that are maintained by the JDBC Connection Pool. More than one JDBC Resource is allowed to point to the same JDBC Connection Pool. In such a case, the physical connection pool is shared by all the resources.
JDBC Connection Pools can be defined and configured by using the web-based Admin Console or by editing the jdbc-connection-pool element in the server.xml file. Though each defined pool is instantiated at server start-up, the pool is only populated with physical connections when accessed for the first time.
The following are the attributes that can be specified for a JDBC connection pool: