Let us check if our app is responding properly to the HTTP requests. As this terminal cannot take any input without quitting serving the Bottle application, we need to login to our VPS with another terminal.
After logging into the VPS with another terminal, you can navigate to your application by typing the following code in the new terminal. Lynx is a command line browser and is usually installed by default in various Linux distributions like Debian and Ubuntu.
If you see the following output, it means your app is working fine. Please note that there is a bug in ab, and it is not able to test the application on the localhost.
So we will change the host from localhost to You can observe how the various values of the ab outcome have changed as compared to the initial test. In the previous tests of ab, we have used the default web server bundled in the Bottle framework. Now we will change the single-threaded default web server with a multi-threaded one. Therefore, let us install a multi-threaded web server library like cherrypy or gunicorn and tell Bottle to use it.
Observe how the Requests per second increased from to It means gunicorn is suitable as a production server for python apps. In this chapter, we will learn how to test multiple URLs concurrently. For that, we will need to edit our application file, app.
You can do this by creating a shell script, with multiple ab calls. Create a file test. To avoid repetition and purpose of clarity, we will show only the relevant of the ab output, indicating by dots what portion has been omitted, as in the following.
You can save the Apache Bench Output to file by creating a shell script, with multiple ab calls. For example, our file test. You can check that the above script has created two files, test1. While using ab, you should be alert to the failed test without warning. For example, if you check a wrong URL, you may get something similar to the following we have deliberately changed the port here. In this chapter, we will understand the preparation required for testing dynamic pages.
A server-side dynamic web page is a web page the construction of which is controlled by an application server processing server-side scripts. The apache bench can only load test the server-side dynamic web page. In this section, we will describe the use of some important flags with the ab command. We will use the terms, options and flags, interchangeably.
The verbose option can be used to analyze and debug if there exist multiple number of failed requests. A common indication of failure of the load test is that the test finishes very fast and it gives a good number for request per second value. But it will be a wrong benchmark. Of course, if you are testing variable responses or returning non HTTP codes in the event of any error, you should simply ignore length checking with the -l option. We will soon see non HTTP when we will launch a web2py application in the subsequent chapters.
When the client sends HTTP request, the connection is made to the server, the server sends the response, and the connection is closed after it has sent the request.
This cycle continues with each request. However, with the keep-alive setting also known as persistent connections , the client maintains an underlying TCP connection open to facilitate multiple requests and response; this eliminates the slow and costly connection initialization time that would otherwise be present. If the web page is of variable length, then you should make use of the option -l. Apache Bench does not report errors if the length of the responses is not constant.
This can be useful for dynamic pages. How to force ab not to exit on receiving errors? You should use the option -r. Without this option, your test may break as soon as any request hits the socket error. However, with this option, errors will be reported in the failed errors heading, but the test will continue till the end.
This option is used to add arbitrary header line. The argument is typically in the form of a valid header line, containing a colon-separated field-value pair i. In the following section, we will learn in detail how to use the above options in combination with the option to use the cookie value, i.
Moreover, it gets installed automatically with Apache web server, or it can be installed separately as Apache utility. It does not have all the features of more popular tools such as jMeter or Grinder, but it is good for a start. This tutorial is designed for Application Developers and System Administrators, who are willing to learn Apache Bench in simple and easy steps.
This tutorial will give you practical knowledge on Apache Bench, and after completing this tutorial, you will be at an intermediate level of expertise from where you can take yourself to higher level of expertise.
Before proceeding with this tutorial, you should have a basic understanding of command line interface CLI , HTTP, text editor and web servers, etc.
This will only be printed if SSL is used. Document Length This is the size in bytes of the first successfully returned document. If the document length changes during testing, the response is considered an error. Concurrency Level The number of concurrent clients used during the test Time taken for tests This is the time taken from the moment the first socket connection is created to the moment the last response is received Complete requests The number of successful responses received Failed requests The number of requests that were considered a failure.
If the number is greater than zero, another line will be printed showing the number of requests that failed due to connecting, reading, incorrect content length, or exceptions. Write errors The number of errors that failed during write broken pipe. Non-2xx responses The number of responses that were not in the series of response codes. If all responses were , this field is not printed. Keep-Alive requests The number of connections that resulted in Keep-Alive requests Total body sent If configured to send data as part of the test, this is the total number of bytes sent during the tests.
This field is omitted if the test did not include a body to send. Total transferred The total number of bytes received from the server. Apache Bench Syntax. Document Length: The byte size of the first successfully returned document. Concurrency Level: The number of concurrent clients used during the test.
Time Taken for Tests: Total time taken to perform the test. Complete Requests : Total number of successful responses received. Failed Requests: Total number of failed requests. Total Transferred: Total number of bytes received from the webserver. Requests per Second: Total number of requests per second.
Time per Request: This is the average time spent per request. Apache Bench Examples. Example 1. Example 2. Example 3. Example 4. Example 5. Consent of the testing server owner as testing may be interpreted as a DDOS attack.
Firewall block The server being tested should whitelist the testing server in the firewall temporarily. Network saturation issues if overused. Different geographical locations. Distance between the servers. Routing congestion or latency. Common Fixes Featured Articles Getting Started Other Products
0コメント