MAIN MENU
Blog di Devolutions

Annunci, aggiornamenti e approfondimenti di Devolutions.

Devolutions PowerShell Universal Test Siege On Ubuntu for the Devolutions blog.

Benchmarking di applicazioni web con Siege su Ubuntu e PowerShell Universal

Questa guida mostra come installare Siege su Ubuntu, raggiungere un host Windows da WSL2, creare un semplice endpoint REST in PowerShell Universal ed eseguire benchmark Siege con la concorrenza predefinita e una concorrenza più elevata.

In questo post vedremo come eseguire il benchmarking di un’applicazione web con Siege su Ubuntu e PowerShell Universal.

Siege è uno strumento di stress test HTTP e HTTPS per Linux. Può eseguire richieste web con un numero configurabile di thread. In modalità benchmark, viene eseguito il più velocemente possibile, senza ritardi.

Sto usando Ubuntu 20.04 in WSL2 su un host Windows 11. In genere usiamo Siege per i test di prestazioni di PowerShell Universal; quindi questa è l’applicazione sotto test qui.

Installare Siege

Per installare Siege su Ubuntu, esegua i seguenti comandi:

sudo apt update -y
sudo apt install siege -y
siege --version

Recuperare l’indirizzo IP dell’host

Affinché l’immagine Ubuntu raggiunga l’host Windows, recuperi l’IP dell’host da /etc/resolv.conf. Il comando seguente stampa l’indirizzo IP direttamente nel terminale:

grep -m 1 nameserver /etc/resolv.conf | awk '{print $2}'
172.18.224.1

Il Suo IP sarà diverso; usi il valore restituito dalla Sua macchina nei passaggi successivi.

Avviare l’applicazione web

Ho PowerShell Universal installato come servizio, in ascolto sulla porta predefinita 5000. Per questo test, crei un endpoint API con New-PSUEndpoint:

New-PSUEndpoint -Url /benchmark -Method GET -Endpoint {
    "Hello, world"
}

Può richiamare l’endpoint in locale con PowerShell:

Invoke-RestMethod http://localhost:5000/benchmark

Da WSL2, richiami lo stesso endpoint con wget, usando l’IP della macchina host del passaggio precedente:

wget http://172.18.224.1:5000/benchmark
--2022-04-13 07:21:35--  http://172.18.224.1:5000/benchmark
Connecting to 172.18.224.1:5000... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/json]
Saving to: ‘benchmark’

benchmark                         [ <=>                                              ]      12  --.-KB/s    in 0s

2022-04-13 07:21:35 (1.95 MB/s) - ‘benchmark’ saved [12]

Eseguire un benchmark Siege

Per eseguire Siege in modalità benchmark, usi il flag -b e passi l’URL da misurare. Per impostazione predefinita, avvia con 25 utenti concorrenti:

siege -b http://172.18.224.1:5000/benchmark

Ho lasciato girare il benchmark per un po’, poi ho premuto Ctrl+C per interromperlo. Questa esecuzione è durata circa 67 secondi a circa 1.000 richieste al secondo:

** SIEGE 4.0.4
** Preparing 25 concurrent users for battle.
The server is now under siege...^C
Lifting the server siege...
Transactions:                  72893 hits
Availability:                 100.00 %
Elapsed time:                  67.34 secs
Data transferred:               2.64 MB
Response time:                  0.02 secs
Transaction rate:            1082.46 trans/sec
Throughput:                     0.04 MB/sec
Concurrency:                   24.96
Successful transactions:       72893
Failed transactions:               0
Longest transaction:            0.51
Shortest transaction:           0.01

Può aumentare il numero di thread di richieste HTTP concorrenti con il parametro -c:

siege -c 125 -b http://172.18.224.1:5000/benchmark

Conclusione

In questo post abbiamo visto come installare Siege su Ubuntu in WSL2, esporre un semplice endpoint PowerShell Universal ed eseguire benchmark Siege contro di esso da Linux.

Vuole provarlo Lei stesso? Scarichi PowerShell Universal dal centro download.