Measure Performance Using IBM i Apache Directives

Apache HTTP Server ProjectSpeed is critical when serving APIs and web pages from IBM i. How can we measure our speed? The IBM HTTP Server (powered by Apache) for i can log the speed of each request, but this capability needs to be turned on.

Default values in the Apache access log include the request’s URL, the HTTP status code, size of the response in bytes, and the user agent (e.g. browser type), but not how long the request took. Let’s see how to add the timing.

Add the timing

The IBM i’s Create HTTP Server wizard produces a configuration file (httpd.conf) that includes this logging directive:

LogFormat "%h %T %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

To add the duration, you can add %D  to the LogFormat string. %D logs the processing time in milliseconds for each complete round-trip request from a browser or API client to your Apache server and back.

In the following LogFormat example, I’d added %D after a label of “microsecs:”

LogFormat "%h %T %l %u %t \"%r\" %>s %b microsecs: %D \"%{Referer}i\" \"%{User-Agent}i\"" combined

I sent a couple of requests to an Apache server that used this LogFormat string. Here’s what was logged:

10.6.4.169 3 - - [01/Jul/2023:12:09:09 -0400] "GET /api/getCustomerList HTTP/1.1" 200 11049946 microsecs: 3249688 "-" "AHC/1.0"

10.6.12.58 0 - - [01/Jul/2023:13:36:40 -0400] "POST /api/insuranceApplication HTTP/1.1" 200 107 microsecs: 105024 "-" "AHC/1.0"

Notice the speed value after “microsecs:” and the number of bytes (represented by %b in the format). One request, which served over 11 MB in data, required over three seconds to return the data, while another, returning only 107 bytes, took about one tenth of a second.

If you prefer your duration measured in seconds rather than microseconds, use the %T parameter instead of %D.

Find the slowdown, which might NOT be your fault

Using these directives is an easy way to see if there are any particularly slow requests processed by your Apache server. The directives are especially expedient for diagnosing slow performance between Cloud applications (NetSuite, Microsoft Dynamics 365, Salesforce, etc.) that may call an API gateway, which in turn calls your IBM i Apache API endpoint.

If you’re being told your API is slow, add %D.

If you’re being told your API is slow, add %D. If the slowness is on your end, fix it. If not, show them the log that was generated, and you can demonstrate that the issue must be further up the chain.

To eliminate network delays

Because %D measures the complete round-trip from browser or API client to your server and back, the response time includes any network delays. To reduce or eliminate network delays in your timing, my trick is to call my IBM i application directly from the IBM i server using curl.

Learn more about Apache Log Directives

For details of each logging option (%h, %T, %l, etc.) in the LogFormat directive above, and other logging elements you can add, see the Apache documentation’s Custom Log Formats section.

These directives are another example of how good the Apache Web server is and how its IBM i integration makes things simpler. For additional help in getting the most from your Apache Web Server, see Apache for IBM i: Where to Find Documentation.

2 replies
    • Alan Seiden
      Alan Seiden says:

      Felipe, happy to help! Wishing you success with your IWS projects. If you choose the Apache web server option with IWS, you get all the Apache features, such as the performance timer described here.

      Reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.