Maggio 08, 2024

Test di carico http con Apache Benchmark e Httperf

In questo articolo mostrerò alcuni esempi di utilizzo di due tool usati per effettuare dei test di carico http su web server: ApacheBenchmark (ab) e Httperf. Bisogna precisare che di default entrambi non simulano propriamente sessioni http in un browser ma effettuano dei test solo sul payload http di un’applicazione web. Questo significa che non viene effettuato il download completo di tutte le risorse presenti nella url sottoposta a test, come per esempio css, immagini, javascript ecc, ma solo il rendering della singola pagina html. Supponiamo per esempio di voler testare una url del tipo http://mywebserver/index.html. Questo il sorgente della pagina index.html.

<html>
<head>
    <script type="text/javascript" src="http://server/jquery.min.js"></script>
</head>

<body>
<div>Test</div>
<div><img src="http://server/image.png"></div>
</body>
</html>

Durante l’esecuzione del test solo la singola pagina index.html sarà rederizzata e non le risorse “jquery.min.js” e “image.png” dichiarate all’interno di essa.

Sia AB sia HTTPERF possono tuttavia effettuare test su connessioni concorrenti, test di carico su numero di request per connessione ecc, e fornire dei risultati che possono essere valutati per capire il livello di performance di un server web. Impostando una configurazione più avanzata, Httperf inoltre, permette la generazione di una serie di URI da passare al test simulando una singola sessione di navigazione. Utilizzando infatti il parametro “wsesslog” è possibile generare una sequenza di accessi a URI diverse, simulando di fatto una carico di sessione piuttosto che di singole request.

Esistono altri tool più avanzati come  SiegeJmeter o OpenSTA che simulano un reale utilizzo di un sito web, ma non saranno trattati in questo articolo. Vediamo ora alcuni esempi di utilizzo di AB e HTTPERF.

ApacheBenchmark

$ ab -n1 -c1 -t1 -k http://mydomain.com/media.html

-n ........ 1 of HTTP requests
-c ........ 1 concurrent connections
-t ........ 1 of seconds of the teest
-k ........ enable HTTP keep-alives

 

$ ab -n10000 -c100 -t10 -k http://alfresco:8080/alfresco/d/d/workspace/SpacesStore/5a101184-beea-4b12-999e-488774c508a2/Alfresco_Developer_Guide.pdf/

$ ab -n  10000 -c100 -t10 -k http://liferay:8080/test-2/

-n ........ 10000 of HTTP requests
-c ........ 100 concurrent connections
-t ........ 10 of seconds of the test
-k ........ enable HTTP keep-alives

Httperf

$ httperf --server=mydomain.com --port=80 --uri=/web/guest/home --hog --num-conns=100 --rate=100 --num-calls=1

--num-conns ........ 100 connections - the total number of connections to create
--rate ............. 100 connections per second - the fixed rate at which connections or sessions are created
--num-call .......... 1 calls - the total number of calls to issue on each connection before closing it

 

$ httperf --server=mydomain.com --port=80 --uri=/web/guest/home --hog --rate=10 --num-conns=100	

--num-conns ........ 100 connections - the total number of connections to create
--rate ............. 10 connections per second - the fixed rate at which connections or sessions are created
--num-call .......... 1 calls - the total number of calls to issue on each connection before closing it

 

# Get a pdf document from the public Alfresco guest home
$ httperf --server=alfresco.it --port=8080 --uri=/alfresco/d/d/workspace/SpacesStore/5a101184-beea-4b12-999e-488774c508a2/Alfresco_Developer_Guide.pdf --rate=100 --hog --num-conns=1000 --num-calls=1

--num-conns ........ 1000 connections - the total number of connections to create
--rate ............. 100 connections per second - the fixed rate at which connections or sessions are created
--num-call .......... 1 calls - the total number of calls to issue on each connection before closing it

 

Related posts

Leave a Reply

Your email address will not be published.