How to Perform Web Server Performance Benchmarkieren?
Kennst du deine durchschnittliche Antwortzeit der Website? Do you know how many concurrent users your site can handle?
Lasttests sind wichtig, damit Webanwendungen die Website kennen Kapazität. Wenn Sie den Webserver auswählen möchten, müssen Sie zunächst die Lasttests durchführen und feststellen, welcher für Sie gut geeignet ist.
Benchmarking can help you to decide;
- Welcher Webserver funktioniert am besten?
- Anzahl der Server, die Sie bedienen müssen x Anzahl der Anforderungen
- Welche Konfiguration liefert Ihnen die besten Ergebnisse?
- Welche Tech-Stacks schneiden besser ab?
- Wenn Ihre Site langsamer oder ausfällt
Es gibt mehrere Online-Tools zur Durchführung eines Stresstests; however, if you are looking for an in-house solution or want to benchmark just the webserver performance, then you can use ApacheBench und alternativ einige der unten aufgeführten Tools.
Ich habe den Apache & Nginx-Webserver verwendet, auf dem gehostet wird DigitalOcean um es zu testen.
ApacheBench
ApacheBench (ab) is an open-source command-line program that works with any web server. In this post, I will explain how to install this small program and perform the load test to benchmark the results.
Apache
Let’s get ApacheBench installed by using a yum command.
yum install httpd-tools
Wenn Sie bereits über httpd-tools verfügen, können Sie dies ignorieren.
Now, let’s see how it performs for 5000 requests with a concurrency of 500.
[root@lab ~]# ab -n 5000 -c 500 http://localhost:80/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient)
Completed 500 requests
Completed 1000 requests
Completed 1500 requests
Completed 2000 requests
Completed 2500 requests
Completed 3000 requests
Completed 3500 requests
Completed 4000 requests
Completed 4500 requests
Completed 5000 requests
Finished 5000 requests
Server Software: Apache/2.2.15
Server Hostname: localhost
Server Port: 80
Document Path: /
Document Length: 4961 bytes
Concurrency Level: 500
Time taken for tests: 13.389 seconds
Complete requests: 5000
Failed requests: 0
Write errors: 0
Non-2xx responses: 5058
Total transferred: 26094222 bytes
HTML transferred: 25092738 bytes
Requests per second: 373.45 [#/sec] (mean)
Time per request: 1338.866 [ms] (mean)
Time per request: 2.678 [ms] (mean, across all concurrent requests)
Transfer rate: 1903.30 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 42 20.8 41 1000
Processing: 0 428 2116.5 65 13310
Waiting: 0 416 2117.7 55 13303
Total: 51 470 2121.0 102 13378
Percentage of the requests served within a certain time (ms)
50% 102
66% 117
75% 130
80% 132
90% 149
95% 255
98% 13377
99% 13378
100% 13378 (longest request)
[root@lab ~]#
Wie Sie sehen können, hat Apache damit umgegangen 373 Anfragen pro Sekunde, und es dauerte insgesamt 13.389 Sekunden, um die Gesamtanforderungen zu bedienen.
Jetzt wissen Sie, dass die Standardkonfiguration diese vielen Anforderungen erfüllen kann. Wenn Sie Konfigurationsänderungen vornehmen, können Sie den Test erneut durchführen, um die Ergebnisse zu vergleichen und die auszuwählen beste eins.
Nginx
Lassen Sie uns testen, was wir für Apache getan haben, damit Sie vergleichen können, welche besser abschneidet.
[root@lab ~]# ab -n 5000 -c 500 http://localhost:80/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient)
Completed 500 requests
Completed 1000 requests
Completed 1500 requests
Completed 2000 requests
Completed 2500 requests
Completed 3000 requests
Completed 3500 requests
Completed 4000 requests
Completed 4500 requests
Completed 5000 requests
Finished 5000 requests
Server Software: nginx/1.10.1
Server Hostname: localhost
Server Port: 80
Document Path: /
Document Length: 3698 bytes
Concurrency Level: 500
Time taken for tests: 0.758 seconds
Complete requests: 5000
Failed requests: 0
Write errors: 0
Total transferred: 19660000 bytes
HTML transferred: 18490000 bytes
Requests per second: 6593.48 [#/sec] (mean)
Time per request: 75.832 [ms] (mean)
Time per request: 0.152 [ms] (mean, across all concurrent requests)
Transfer rate: 25317.93 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 6 11.0 2 53
Processing: 5 19 8.2 17 53
Waiting: 0 18 8.2 16 47
Total: 10 25 17.4 18 79
Percentage of the requests served within a certain time (ms)
50% 18
66% 21
75% 21
80% 22
90% 69
95% 73
98% 75
99% 76
00% 79 (longest request)
[root@lab ~]#
WOW!
Hast du das gesehen?
Nginx behandelt 6593 Anfragen pro Sekunde! Ein Gewinner.
Wenn Sie also nur zwei Webserver vergleichen, erhalten Sie eine Vorstellung davon, welchen Sie für Ihre Webanwendung auswählen sollen.
The above test is on CentOS 6.8, 64 bit. You can try multiple combinations of OS & Web Server version for the optimal results.
Don’t like ApacheBench for whatever reason? No worries, there are plenty of others you can use to perform HTTP load.
BELAGERUNG
BELAGERUNG ist ein HTTP-Lasttest-Dienstprogramm, das unter UNIX unterstützt wird. Sie können mehrere URLs in eine Textdatei einfügen, um Tests zu laden. Sie können Belagerung mit yum installieren.
# yum Belagerung installieren
Let’s run the test with 500 concurrent requests for 5 seconds.
[root@lab ~]# siege -q -t 5S -c 500 http://localhost/ Lifting the server siege... done. Transactions: 4323 hits Availability: 100.00 % Elapsed time: 4.60 secs Data transferred: 15.25 MB Response time: 0.04 secs Transaction rate: 939.78 trans/sec Throughput: 3.31 MB/sec Concurrency: 37.97 Successful transactions: 4323 Failed transactions: 0 Longest transaction: 1.04 Shortest transaction: 0.00 [root@lab ~]#
Parameter aufschlüsseln.
-q - um es leise auszuführen (ohne Anforderungsdetails)
-t - 5 Sekunden lang laufen lassen
-c – 500 concurMietanfragen
Wie Sie sehen können, beträgt die Verfügbarkeit 100% und die Antwortzeit 0.04 Sekunden. Sie können den Lasttestparameter basierend auf Ihrem Ziel anpassen.
Ali
Ali is a relatively new load testing tool to perform real-time analysis. It supports multiple platforms to install, including Docker.
Nach der Installation ausführen ali
um die Nutzungsdetails zu sehen.
root@lab:~# ali
no target given
Usage:
ali [flags] <target URL>
Flags:
-b, --body string A request body to be sent.
-B, --body-file string The path to file whose content will be set as the http request body.
--debug Run in debug mode.
-d, --duration duration The amount of time to issue requests to the targets. Give 0s for an infinite attack. (default 10s)
-H, --header strings A request header to be sent. Can be used multiple times to send multiple headers.
-k, --keepalive Use persistent connections. (default true)
-M, --max-body int Max bytes to capture from response bodies. Give -1 for no limit. (default -1)
-m, --method string An HTTP request method for each request. (default "GET")
-r, --rate int The request rate per second to issue against the targets. Give 0 then it will send requests as fast as possible. (default 50)
-t, --timeout duration The timeout for each request. 0s means to disable timeouts. (default 30s)
-v, --version Print the current version.
Examples:
ali --duration=10m --rate=100 http://host.xz
Author:
Ryo Nakao <ryo@nakao.dev>
root@lab:~#
As you can see above, you have an option to send HTTP headers, test duration, rate limit, timeout, and more. I did a quick test on Geekflare Tools und hier sieht die Ausgabe so aus.
The report is interactive and gives detailed latency-Informationen.
Gobench
Gobench is written in Go language and simple load testing utility to benchmark the web server performance. It supports more than 20,000 concurrent users which ApacheBench nicht.
Apache JMeter
JMeter ist eines der beliebtesten Open-Source-Tools zur Messung der Leistung von Webanwendungen. JMeter ist eine Java-basierte Anwendung und nicht nur ein Webserver, sondern Sie können sie auch gegen PHP und Java verwenden. ASP.net, SOAP, REST usw.
JMeter got decent friendly GUI, and the latest version 3.0 require Java 7 or higher to launch the application. You must give a try to JMeter if your goal is to optimize the web application performance.
WRK
WRK is another modern performance measurement tool to put a load on your web server and give you latency, request per second, transfer per second, etc. details.
Mit wrk können Sie festlegen, dass ein Auslastungstest mit mehreren Threads ausgeführt werden soll.
Let’s take an example of running a test for 5 minutes with 500 concurrent users with 8 threads.
wrk –t8 –c500 -d300s http://localhost
Autokanone
Inspiriert von der Arbeit, Autokanone ist in Node.js geschrieben. Sie können es programmatisch verwendenally, über API oder eigenständiges Dienstprogramm. Alles was Sie brauchen ist NodeJS installiert als Voraussetzung.
You can control a number of connections, requests, duration, workers, timeout, connection rate and offer tons of options to benchmark your web applications.
Curl-Lader
Curl-Loader is written in C to simulate application load, and it supports SSL/TLS. Along with the web page test, you can also use this open-source tool to perform load on FTP servers.
Sie können erstellenate a test plan with a mix of HTTP, HTTPS, FTP, and FTPS in a single batch configuration.
httperf
Der httperf is a high-performance tool that focuses on micro and macro-level benchmarks. It supports HTTP/1.1 and SSL protocols.
If you have the expected number of concurrent users and looking to test if your web server can serve a number of a request, you can use the following command.
httperf --server localhost --port 80 --num-conns 1000 --rate 100
Der obige Befehl testet mit 100 Anforderungen pro Sekunde für 1000 HTTP-Anforderungen.
Tsung
Tsung ist ein verteiltes Multiprotokoll-Stresstest-Tool zur Belastung von HTTP-, SOAP-, PostgreSQL-, LDAP-, XAMP- und MySQL-Servern. Es unterstützt HTTP/1.0, HTTP/1.1 und Cookies werden automatisch erstelltally abgewickelt.
Mit Tsung ist es möglich, einen Bericht zu erstellen.
Fazit
I hope the above benchmarking tools give you an idea about your web server performance and decide what works best for your project.
Als nächstes vergessen Sie nicht monitor your website performance.