Welcome!

Apache Authors: Pat Romanski, Liz McMillan, Elizabeth White, Christopher Harrold, Janakiram MSV

Related Topics: Apache, Java IoT

Apache: Article

Analyzing Load on Apache Web Server

Monitoring performance over any desired time period

A web server plays an increasingly important role in the computing world as the world has shifted away from traditional stand-alone desktop computing to Internet's Client-Server and its variants based computing paradigm. Almost everything on networks is consumed either by using web services or web-pages, for all of which, a web-server is integral. As such, it becomes imperative for organizations to be able to finely monitor their servers' load usage and average performance over different times of day and according to the kind of resources hosted on the server. This raises the need for a solution through which organizations and individuals can monitor their web servers' performance to an arbitrary level of granularity depending on their needs.

This article addresses the same issue and implements an approach for the same in Java programming language.

Problem Statement - Use Case Scenario
Consider the case where you want to monitor the performance of an Apache Web Server for some past time. You would want to know what are the numbers of pages served by the server in that elapsed time span so as to identify the performance as well as utilization of the Web Server.

The mod_status module in the Apache Web Server already provides us with a status file which determines the performance of the server through several statistics including number of worker, requests, time the server has been running since it was started, and number of requests amongst other things.

But a major disadvantage of mod_status file is that it tells us about the average number of requests since the time server was started and this may not reflect the actual performance of the server in various instances. For example, consider that the server was started at 10:00 AM and it ran till 12:00 Noon. In those 2 hours, it server 120 requests. So the number of request returned by mod_status file would be 1 request per minute. But, during that time span, let us say the server was idle between 10:00 - 11:00 AM and it actually server 120 request in a time span of one hour only. So the actual performance would be 2 requests per minute from 11:00-12:00. There is no way in mod_status file to the status for different time instances. It returns the average only from the time it was started to the present time.

In this article we will implement a way to find out the average performance of the server for different time periods without the need to stop/start the server again and again. We will also store those values for a fairly large period in a database so that we can get a better know-how of the server performance over different time periods.

Tech and Services to be Used
We are going to implement the solution in Java and will make use of the below mentioned services and tech:

  1. Apache Web Server: We will be using an instance of Apache Web Serve in order to monitor it and send requests to it to fetch the machine readable status file generated by mod_status module.
  2. A listener to receive the records. In this example we will showcase it through H2 Database. It will be used to store the values fetched from the status module. Any relational database can be used instead of H2. Users are free to register another listener and implement it the way they want.
  3. Servlets and JSP (Optional): The implementation would communicate with the Apache web server using a servlet hosted on tomcat server. The same can be achieved using command line.

Implementation

Let us now delve into the actual implementation of the application. This article uses Eclipse as a development environment and assumes familiarity with Eclipse. The article also assumes that you have an Apache web server installed and running on your system. If you do not have Apache Web Server installed, you can download and install it from http://httpd.apache.org/download.cgi

Implementation Roadmap
In this implementation, we will first get the machine readable file which contains server statistics from the Apache web server. We will store these values in a database for a number of time stamps in a convenient fashion. These values would then be used for the calculation of the average number of requests served for different time periods by the Apache Web Server. In the final step, we will allow this app to be used through a Servlet. Alternatively, users can also issue commands through a command line or design a UI for the same which allows them to specify the time frame for which they want the average number of requests for the Apache Web server.

Enable and Test Status Support for mod_status

In order to get the server statistics from mod_status, you first have to enable it so that it can be queried to generate the status file. In order to do so, go to the Apache Web Server installation directory and traverse to the httpd.conf file in the conf directory and add the following to the file:

Also, edit the httpd.conf and mark ExtendedStatus of the server as On.

ExtendedStatus On

You should be able to get the server statistics now. Hit the following URL in the web browser to get the status file:

http://your.server.name/server-status

The file is generated in two formats. One is the human readable one, which is what you get when you hit the above mentioned URL in the browser. The second is the machine readable file, which is like a normal text file and can be directly used by an application to use the statistics reported by the file. For our purpose, we will be calling this machine readable file directly from our application. The machine readable file can be accessed by using the following link:

http://your.server.name/server-status?auto

Create a Listener:
You can extend the IApacheSnapshotProcessor interface which has two methos.  The implementation is upto the user. A sample implementation in provided through H2Persiter which extends the IApacheSnapshotProcessor interface.

Create Schema in H2
As a second step, we will create a schema and a table for storing the values retrieved from the machine readable file. The application would repeatedly ping the Apache Web server URL to get the machine readable file at different time intervals. We will be parsing the values obtained from the file and store them in the database for future use.

Download and install the H2 database from http://www.h2database.com/html/main.html.

Connect to H2 using the following credentials:

Create a schema and table in H2 to store the values. The table should contain the following fields:

1.        ID (serves as the primary key)

2.       TOTAL_ACCESS (for storing the total number of accesses from the time server started running)

3.       TOTAL_KBYTES (total number of KBs since the time server was running)

4.       UPTIME

5.       REQ_PS

6.       BYTES_PS

7.       BYTES_PR

8.       BUSY_WORKER

9.       IDLE_WORKER

10.   SNAPSHOT_TIME_DIFF (this field will be used as integer count for the count difference between the number of request at the time first server snapshot was taken and the number of request for which the current snapshot has been taken. So let's say that we take server snapshot every 2 sec and the server started at 10:00 AM. So for the first request at 10:00:00 AM SNAPSHOT_TIME_DIFF value would be 0. At 10:00:02 AM, value would be 1 and so on.)

11.   SNAPSHOT_TIME

Our table is now ready and we can use it to store values of all the fields which we get from the mod_status file.

Getting Values from the Machine Readable File
We now have to get the values from the machine readable mod_status file and parse them before storing those values into the database. Create a class (RequestCounter.java) which will access the URL at regular intervals, will read the file, and parse the values into variables, and these variables will then be passed on to a persister class which will then store them in the database.

We will first construct the URL in the proper format as required by Apache Web Server in a method (pool())

This method will again call the pool() method which will then get the Apache Server status from inside of a method (TimerTask). This method will run till the time we have specified. Suppose, we want to store the values for last 2 hours, then we can set the timer for that time period. After that time period is elapsed, it will call the cancel() method and will stop hitting the Apache Web Server URL.

getApacheStatus(url); calls the method which gets the machine readable file.

Once we have the file, we read it line by line and parse it and store the values in private variables.

Storing Values in the Database
Once we have the parsed values from the file, we now need to store them into the database. For this, create a file (H2Persister.java) which will create a connection to the database and will insert values in the database. Later on, we will use the same file to get average performance values from the database as well.

Create a method (connect()) which will create a JDBC connection object for the database.

Class.forName("org.h2.Driver"); specifies the JDBC driver name. We get the connection from DriverManager using getConnection method, and this assign this to conn variable which is an instance of the Connection object.

Create a method (process()), which will take as arguments the values which we parsed, and will then prepare an sql query and store those values in the database by executing that query.

Statement stmt = conn.createStatement();creates a Statement object. We prepare a query which will insert the values into the database.

String sql = "insert into APACHE_MOD_STATUS.COUNT_HANDLER values (DEFAULT," + TOTAL_ACCESS + "," + TOTAL_KBYTES + "," + UPTIME + "," + REQ_PS + "," + BYTES_PS + "," + BYTES_PR + "," + BUSY_WORKER + "," + IDLE_WORKER     + "," + (System.currentTimeMillis() / 1000 - startupTime) + ", DEFAULT" + ")";

Afterwards, we execute the query to insert the values in the database.

We call this process() method from our previously created RequestCounter file and pass the values which we parsed there to the process() method.

hPersister.process(totalAccesses, totalKBytes, uptime, reqPerSec, ytesPerSec, bytesPerReq, busyWorkers,idleWorkers);

Getting Average Values

We now have to have a mechanism to get the values stored in the database and process them to get the average number of requests during the time frame requested by the user. For this, create a method (getAverage) in H2Persister.java file which will do the same. This method takes the time frame as an argument. First of all, create a SQL query to retrieve the desired values from the database. For our purpose, we need Total_ACCESS and UPTIME fields values from the database. The following query does just that:

String sql = "SELECT ID,TOTAL_ACCESS,UPTIME FROM APACHE_MOD_STATUS.COUNT_HANDLER where SNAPSHOT_TIME_DIFF>"    + (System.currentTimeMillis() / 1000 - startupTime - timeslot - 1);

Statement stmt = conn.createStatement();

ResultSet rs = stmt.executeQuery(sql);

Create an ArrayList which will store the values retrieved by the ResultSet object.

ArrayList<RPSTuple> rpsTupleList = new ArrayList<RPSTuple>();

This ArrayList is of the type RPSTuple which has two private fields totalAccess and uptime and getter and setter methods for the same.

Iterate over the ResultSet object rs and store the values into the ArrayList one by one.

Once we have the desired values in the ArrayList, let us now process them to get the average number of requests for the server over the specified period of time.

From the rpsTupleList, we first get its first node and last node.

From this, we get the average by subtracting total access numbers of last node from first node, and divide that by difference of first node and last node uptime.

lastNode.getTotalAccess()-firstNode.getTotalAccess()) / (lastNode.getUptime()-firstNode.getUptime()

This gives us the performance of an Apache Web Server link in terms of average number of requests over a desired time frame and not just the time frame from which the server started running to the current one.

Create a Servlet
We will now create a Servlet (CounterServlet.java) which will display the average number of requests which we get from the above.

In addition to a Servlet, one can also call the same app from a command line as well.

Summary
This article describes the process of monitoring an Apache Web Server link performance by giving the users and system administrators the facility to monitor the performance over any desired time period. This enables the users more control over the unraveling and understanding of the usage statistics of their servers over different periods of time so that they can better utilize their systems according to peak loads and various other factors.

More Stories By Peeyush Taori

Peeyush Taori is a Senior Systems Engineer with Infosys Technologies Limited and has worked in Java Technology Domain for more than 5 years

More Stories By Kumar Tiwari

Kumar Manava Tiwari has six years of IT experience. He has worked in Cloud Computing, software factories, enterprise application development and application frameworks development. He is currently working as a Technology Lead with Infosys Technologies Limited, India.

@ThingsExpo Stories
Nordstrom is transforming the way that they do business and the cloud is the key to enabling speed and hyper personalized customer experiences. In his session at 21st Cloud Expo, Ken Schow, VP of Engineering at Nordstrom, discussed some of the key learnings and common pitfalls of large enterprises moving to the cloud. This includes strategies around choosing a cloud provider(s), architecture, and lessons learned. In addition, he covered some of the best practices for structured team migration an...
Recently, REAN Cloud built a digital concierge for a North Carolina hospital that had observed that most patient call button questions were repetitive. In addition, the paper-based process used to measure patient health metrics was laborious, not in real-time and sometimes error-prone. In their session at 21st Cloud Expo, Sean Finnerty, Executive Director, Practice Lead, Health Care & Life Science at REAN Cloud, and Dr. S.P.T. Krishnan, Principal Architect at REAN Cloud, discussed how they built...
In his session at 21st Cloud Expo, Raju Shreewastava, founder of Big Data Trunk, provided a fun and simple way to introduce Machine Leaning to anyone and everyone. He solved a machine learning problem and demonstrated an easy way to be able to do machine learning without even coding. Raju Shreewastava is the founder of Big Data Trunk (www.BigDataTrunk.com), a Big Data Training and consulting firm with offices in the United States. He previously led the data warehouse/business intelligence and B...
In his Opening Keynote at 21st Cloud Expo, John Considine, General Manager of IBM Cloud Infrastructure, led attendees through the exciting evolution of the cloud. He looked at this major disruption from the perspective of technology, business models, and what this means for enterprises of all sizes. John Considine is General Manager of Cloud Infrastructure Services at IBM. In that role he is responsible for leading IBM’s public cloud infrastructure including strategy, development, and offering m...
With tough new regulations coming to Europe on data privacy in May 2018, Calligo will explain why in reality the effect is global and transforms how you consider critical data. EU GDPR fundamentally rewrites the rules for cloud, Big Data and IoT. In his session at 21st Cloud Expo, Adam Ryan, Vice President and General Manager EMEA at Calligo, examined the regulations and provided insight on how it affects technology, challenges the established rules and will usher in new levels of diligence arou...
The 22nd International Cloud Expo | 1st DXWorld Expo has announced that its Call for Papers is open. Cloud Expo | DXWorld Expo, to be held June 5-7, 2018, at the Javits Center in New York, NY, brings together Cloud Computing, Digital Transformation, Big Data, Internet of Things, DevOps, Machine Learning and WebRTC to one location. With cloud computing driving a higher percentage of enterprise IT budgets every year, it becomes increasingly important to plant your flag in this fast-expanding busin...
Smart cities have the potential to change our lives at so many levels for citizens: less pollution, reduced parking obstacles, better health, education and more energy savings. Real-time data streaming and the Internet of Things (IoT) possess the power to turn this vision into a reality. However, most organizations today are building their data infrastructure to focus solely on addressing immediate business needs vs. a platform capable of quickly adapting emerging technologies to address future ...
No hype cycles or predictions of a gazillion things here. IoT is here. You get it. You know your business and have great ideas for a business transformation strategy. What comes next? Time to make it happen. In his session at @ThingsExpo, Jay Mason, an Associate Partner of Analytics, IoT & Cybersecurity at M&S Consulting, presented a step-by-step plan to develop your technology implementation strategy. He also discussed the evaluation of communication standards and IoT messaging protocols, data...
22nd International Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, and co-located with the 1st DXWorld Expo will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud ...
22nd International Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, and co-located with the 1st DXWorld Expo will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud ...
DevOps at Cloud Expo – being held June 5-7, 2018, at the Javits Center in New York, NY – announces that its Call for Papers is open. Born out of proven success in agile development, cloud computing, and process automation, DevOps is a macro trend you cannot afford to miss. From showcase success stories from early adopters and web-scale businesses, DevOps is expanding to organizations of all sizes, including the world's largest enterprises – and delivering real results. Among the proven benefits,...
@DevOpsSummit at Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, is co-located with 22nd Cloud Expo | 1st DXWorld Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The widespread success of cloud computing is driving the DevOps revolution in enterprise IT. Now as never before, development teams must communicate and collaborate in a dynamic, 24/7/365 environment. There is no time to wait...
Cloud Expo | DXWorld Expo have announced the conference tracks for Cloud Expo 2018. Cloud Expo will be held June 5-7, 2018, at the Javits Center in New York City, and November 6-8, 2018, at the Santa Clara Convention Center, Santa Clara, CA. Digital Transformation (DX) is a major focus with the introduction of DX Expo within the program. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive ov...
SYS-CON Events announced today that T-Mobile exhibited at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. As America's Un-carrier, T-Mobile US, Inc., is redefining the way consumers and businesses buy wireless services through leading product and service innovation. The Company's advanced nationwide 4G LTE network delivers outstanding wireless experiences to 67.4 million customers who are unwilling to compromise on qua...
SYS-CON Events announced today that Cedexis will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Cedexis is the leader in data-driven enterprise global traffic management. Whether optimizing traffic through datacenters, clouds, CDNs, or any combination, Cedexis solutions drive quality and cost-effectiveness. For more information, please visit https://www.cedexis.com.
SYS-CON Events announced today that Google Cloud has been named “Keynote Sponsor” of SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Companies come to Google Cloud to transform their businesses. Google Cloud’s comprehensive portfolio – from infrastructure to apps to devices – helps enterprises innovate faster, scale smarter, stay secure, and do more with data than ever before.
SYS-CON Events announced today that Vivint to exhibit at SYS-CON's 21st Cloud Expo, which will take place on October 31 through November 2nd 2017 at the Santa Clara Convention Center in Santa Clara, California. As a leading smart home technology provider, Vivint offers home security, energy management, home automation, local cloud storage, and high-speed Internet solutions to more than one million customers throughout the United States and Canada. The end result is a smart home solution that sav...
SYS-CON Events announced today that Opsani will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Opsani is the leading provider of deployment automation systems for running and scaling traditional enterprise applications on container infrastructure.
SYS-CON Events announced today that Nirmata will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Nirmata provides a comprehensive platform, for deploying, operating, and optimizing containerized applications across clouds, powered by Kubernetes. Nirmata empowers enterprise DevOps teams by fully automating the complex operations and management of application containers and its underlying ...
SYS-CON Events announced today that Opsani to exhibit at SYS-CON's 21st Cloud Expo, which will take place on October 31 through November 2nd 2017 at the Santa Clara Convention Center in Santa Clara, California. Opsani is creating the next generation of automated continuous deployment tools designed specifically for containers. How is continuous deployment different from continuous integration and continuous delivery? CI/CD tools provide build and test. Continuous Deployment is the means by which...