Tag Archives: benchmark

Linux Palvelimena kotitehtävä #7 | Optimointia

Linux Palvelimena kotitehtävä #7 |

Seitsemännen kotitehtävän tehtävänanto on seuraavanlainen:

h7 optimointia. Lue koko tehtävänanto ja vinkit seuraavasta kommentista ennen kuin ryhdyt työhön. Kuormitustyökaluja saa käyttää ainoastaan omaan koneeseen.
Tee ja raportoi:
– Mittaa omalla koneellasi olevan WordPress-sivun ja samanlaisen staattisen sivun nopeuseroa ‘ab’ työkalulla.
– Asenna Varnish. Mittaa jonkin dynaamisen weppisivun (wordpress tms) suorituskyky ennen ja jälkeen asennuksen. Kuinka suuren hyödyn saat?
Tee ainakin kaksi seuraavista:
a) Muuta jotain Varnishin asetusta VCL-kielellä (esim iso-kuvat suoraan läpi – ei välimuistiin)
b) Analysoi ja nopeuta weppisivua YSlow -lisäkkeen avulla
c) Analysoi ja nopeuta weppisivua Firebug -lisäkkeen Net-välilehden avulla
d) Etsi jokin nopeuden analysoinnissa auttava palvelu wepistä ja käytä sitä
Vinkkejä:
Kuormitustyökaluja (esim ‘ab’) saa käyttää vain omiin koneisiin. Toisten koneiden tai verkkojen häiritseminen kuormitustyökaluilla tulkitaan helposti palvelunestohyökkäykseksi, joten olkaa huolellisia. Helpoin osoite kirjoittaa oikein on “localhost”.
Mittaaminen on optimoinnissa tärkeintä. Ilman mittausta optimointi on pelkkää woodoota ja taikauskoa. Kun mittaat weppipalvelimen suorituskykyä, katso, että palvelin on vastannut jokaiseen hakupyyntöön. Ei varmaankaan ole hyötyä, että palvelin pystyy palvelemaan 20 ziljoonaa virheilmoitusta sekunnissa (Failed requests).
Wepistä löytyy paljon eritasoisia ja -laatuisia ohjeita Apachen optimointiin ja Varnishin käyttöön.
https://eliimatt.wordpress.com/tag/suorituskyky/

Apache 2 performance boost with varnish & YSlow


https://encrypted.google.com/search?q=karvinen+varnish
Jossain edistyneessä ohjeessa automatisoidaan asennuksia Puppetilla, mutta sitä opetellaan vasta “Linuxin keskitetty hallinta” kurssilla, eikä tarvita tässä.
Wordpressin temppuilut:
– Jos uuden WordPress-version sisäänrakennettu välimuisti pienentää eroa etusivulla, tee uusi bloggaus ja mittaa suorituskyky tältä alasivulta.
– Jos uusi WordPress kieltää Cachen, ks
http://terokarvinen.com/2012/aikataulu-linux-palvelimena-ict4tn003-7-ict4tn003-kevaalla-2013#comment-19506

Tehtävä tehdään Virtualboxissa pyörivällä Xubuntu 13.10:lla jossa on jo asennettu LAMP-server ja WordPress.

Käynnistetään kone ja päivitetään pakettivarastot komennolla

$ sudo apt-get update

Kokeiltuani ab-komentoa, minua ystävällisesti kehoitettiin asentamaan se, näin siis teemme.

$ sudo apt-get install apache2-utils

Mitataan ab:lla wordpress-sivustoa.

$ ab -c 500 -n 1000 http://localhost/wordpress/

Kyseisellä kommenolla simuloidaan sitä, jos tulisi 500 HTTP-yhteydellä 1000 HTTP-pyyntöä.

This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
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)
apr_socket_recv: Connection reset by peer (104)
esa@xubVbox:/var/www$ ab -c 500 -n 1000 http://localhost/wordpress/
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
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 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests

Server Software: Apache/2.4.6
Server Hostname: localhost
Server Port: 80

Document Path: /wordpress/
Document Length: 8837 bytes

Concurrency Level: 500
Time taken for tests: 64.551 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 9096000 bytes
HTML transferred: 8837000 bytes
Requests per second: 15.49 [#/sec] (mean)
Time per request: 32275.418 [ms] (mean)
Time per request: 64.551 [ms] (mean, across all concurrent requests)
Transfer rate: 137.61 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 19 112.6 9 1000
Processing: 3658 18032 18873.2 9044 64534
Waiting: 3319 17695 18925.2 8653 64527
Total: 3669 18051 18870.5 9062 64546

Percentage of the requests served within a certain time (ms)
50% 9062
66% 9464
75% 12708
80% 34448
90% 64400
95% 64459
98% 64506
99% 64514
100% 64546 (longest request)

Keskimäärin 15 pyyntöä sekunnissa WordPressin kuormittamiseen.

Seuraavaksi kokeillaan samaa kuormitusta yksittäiseen postaukseen.

$ ab -c 500 -n 1000 http://localhost/wordpress/?p=4/

This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
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 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests

Server Software: Apache/2.4.6
Server Hostname: localhost
Server Port: 80

Document Path: /wordpress/?p=4/
Document Length: 10617 bytes

Concurrency Level: 500
Time taken for tests: 56.493 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 10935000 bytes
HTML transferred: 10617000 bytes
Requests per second: 17.70 [#/sec] (mean)
Time per request: 28246.267 [ms] (mean)
Time per request: 56.493 [ms] (mean, across all concurrent requests)
Transfer rate: 189.03 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 34 163.8 9 1001
Processing: 3565 15696 14897.8 9523 56474
Waiting: 2743 14735 15003.6 8364 56235
Total: 3576 15731 14889.9 9568 56487

Percentage of the requests served within a certain time (ms)
50% 9568
66% 9951
75% 13878
80% 30767
90% 30870
95% 56442
98% 56469
99% 56481
100% 56487 (longest request)

Pyynnössä kesti todella kauan verrattuna ensimmäiseen. En tiedä minkä takia huomattavasti hitaammin tällä kertaa, vain noin 18 pyyntöä sekunnissa kun edellisessä oli yli kaksi tuhatta.

Kokeillaan vielä kuormitusta johonkin yksinkertaiseen staattiseen sivuun.

$ ab -c 500 -n 1000 http://localhost/~esa/index.php

This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
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 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests

Server Software: Apache/2.4.6
Server Hostname: localhost
Server Port: 80

Document Path: /~esa/index.php
Document Length: 74478 bytes

Concurrency Level: 500
Time taken for tests: 3.427 seconds
Complete requests: 1000
Failed requests: 103
(Connect: 0, Receive: 0, Length: 103, Exceptions: 0)
Write errors: 0
Total transferred: 74667882 bytes
HTML transferred: 74477882 bytes
Requests per second: 291.78 [#/sec] (mean)
Time per request: 1713.600 [ms] (mean)
Time per request: 3.427 [ms] (mean, across all concurrent requests)
Transfer rate: 21276.22 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 5 5.5 0 14
Processing: 7 699 932.2 236 3413
Waiting: 3 639 947.2 169 3413
Total: 17 704 935.3 237 3424

Percentage of the requests served within a certain time (ms)
50% 237
66% 311
75% 471
80% 1731
90% 1821
95% 3404
98% 3421
99% 3422
100% 3424 (longest request)

Noin 300 pyyntöä sekunnissa, paljon ripeämmin kuin yksittäisen blogipostauksen kuormitukseen.

Varnishin asentaminen

Asennus onnistuu seuraavanlaisesti

$ sudo apt-get install varnish -y

Koska itsellä ei ole harmainta aavistusta, mikä on Varnish, täytyy jostain katsoa tarkemmin mitä kaikkea pitää tehdä jotta saisi sen toimimaan.

$ sudoedit /etc/apache2/ports.conf

Lisätään Listen 80 rivin perään 80.

Listen 8080

$ sudoedit /etc/default/varnish

Muokattiin seuraavaa riviä

DAEMON_OPTS=”-a :6081 \

Ja uusi rivi näyttää tältä.

DAEMON_OPTS=”-a :80 \

Käynnistetään Apache ja Varnish uudestaan

$ sudo service apache2 restart
$ sudo service varnish restart

Kokeillaan nyt samoja kuormitustestejä kuin ennen Varnishin asennusta.

$ ab -c 500 -n 1000 http://localhost/wordpress/

This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
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 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests

Server Software: Apache/2.4.6
Server Hostname: localhost
Server Port: 80

Document Path: /wordpress/
Document Length: 8837 bytes

Concurrency Level: 500
Time taken for tests: 0.261 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 9155989 bytes
HTML transferred: 8837000 bytes
Requests per second: 3831.96 [#/sec] (mean)
Time per request: 130.482 [ms] (mean)
Time per request: 0.261 [ms] (mean, across all concurrent requests)
Transfer rate: 34263.08 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 10 10.2 17 24
Processing: 31 98 38.4 91 237
Waiting: 29 94 38.0 85 233
Total: 32 108 43.5 92 253

Percentage of the requests served within a certain time (ms)
50% 92
66% 113
75% 141
80% 148
90% 182
95% 193
98% 200
99% 202
100% 253 (longest request)

Kuormitus kesti 0,261 sekuntia, kun taas ennen Varnishia testi kesti yli minuutin. Kokeillaan vielä yksittäiseen WordPress postaukseen ja staattiseen sivustoon tehdä kuormitustestit.

Yksittäiseen blogipostaukseen kuormitustestaus.

$ ab -c 500 -n 1000 http://localhost/wordpress/?p=4/

This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
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 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests

Server Software: Apache/2.4.6
Server Hostname: localhost
Server Port: 80

Document Path: /wordpress/?p=4/
Document Length: 10617 bytes

Concurrency Level: 500
Time taken for tests: 0.367 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 10994989 bytes
HTML transferred: 10617000 bytes
Requests per second: 2723.12 [#/sec] (mean)
Time per request: 183.613 [ms] (mean)
Time per request: 0.367 [ms] (mean, across all concurrent requests)
Transfer rate: 29238.93 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 8 8.5 12 22
Processing: 10 67 40.3 69 264
Waiting: 8 63 39.5 64 264
Total: 10 75 46.4 78 264

Percentage of the requests served within a certain time (ms)
50% 78
66% 99
75% 116
80% 125
90% 135
95% 140
98% 142
99% 152
100% 264 (longest request)

Staattisen sivuston kuormitustestaus

$ ab -c 500 -n 1000 http://localhost/~esa/index.php

This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
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 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests

Server Software: Apache/2.4.6
Server Hostname: localhost
Server Port: 80

Document Path: /~esa/index.php
Document Length: 75163 bytes

Concurrency Level: 500
Time taken for tests: 0.516 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 75412989 bytes
HTML transferred: 75163000 bytes
Requests per second: 1938.32 [#/sec] (mean)
Time per request: 257.956 [ms] (mean)
Time per request: 0.516 [ms] (mean, across all concurrent requests)
Transfer rate: 142748.18 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 9 9.3 14 24
Processing: 5 195 79.3 232 481
Waiting: 5 161 73.4 197 321
Total: 27 205 71.8 234 503

Percentage of the requests served within a certain time (ms)
50% 234
66% 247
75% 254
80% 258
90% 269
95% 276
98% 289
99% 293
100% 503 (longest request)

Hyvin kummallista todeta, että staattisen sivun kuormittamisessa meni kaikista eniten aikaa.

Firebug

Lisätään Firebug-lisäosa Firefoxiin
Tools → Add-ons
kirjoitetaan hakukenttään Firebug ja sen pitäisi listautua ensimmäisenä, asennetaan.

Klikataan Firebugia ja vaihdetaan asetuksia niin, että käyttöliittymä on erillisessä ikkunassa. Firebug UI Location → Detached

Kun saadaan Firebugin käyttöliittymä auki, mennään Net välilehdellä ja painetaan Enable.

Mennään osoitteeseen localhost/wordpress ja katsotaan mitä tietoa Firebug on saanut kerätttyä.

firebug_1
Kuten jotain kuvasta voi päätellä, on verkkosivun hakemiseen kulunut 35 millisekuntia ja muihin siihen liittyviin liitännäisiin muutamia millisekunteja.
Jos sivustolla olisi ollut jotain kuvatiedostoja, olisi varmasti niiden latausaika ollut kaikista suurin.

YSlow

YSlow löytyy samasta paikasta kun Firebug, eli add-ons kohdasta. Kirjoitetaan siihen yslow ja asennetaan tuorein versio joka näytti olevan 3.1.8. Asennus vaatii selaimen uudelleen käynnistämisen.

YSlow löytyy Firebug ohjelmasta Yslow välilehdeltä. Ajetaan testi kun WordPress sivu on auki.

yslow_1

Yhteisarvosanaksi saadaan 90 / 100 ja kaikki paitsi kaksi kohtaa on saanut kouluarvosanan A.

Grade F on Use a Content Delivery Network (CDN)

There are 6 static components that are not on CDN.

You can specify CDN hostnames in your preferences. See YSlow FAQ for details.

fonts.googleapis.com: 1 component, 1.7K (0.4K GZip)

Herjaa kuudesta staattisesta komponentista jota ei löydy CDN:stä.

Grade F on Add Expires headers

There are 7 static components without a far-future expiration date.

Web pages are becoming increasingly complex with more scripts, style sheets, images, and Flash on them. A first-time visit to a page may require several HTTP requests to load all the components. By using Expires headers these components become cacheable, which avoids unnecessary HTTP requests on subsequent page views. Expires headers are most often associated with images, but they can and should be used on all page components including scripts, style sheets, and Flash.

Lähteet:

https://eliimatt.wordpress.com/tag/suorituskyky/
http://www.yolinux.com/TUTORIALS/WebServerBenchmarking.html
http://anttiwirman.com/2014/03/17/linux-palvelimena-ict4tn003-11-ja-12-kevaalla-2014-kotitehtava-7/

Kuormittaminen ja Varnishin asentaminen sekä suorituskyvyn mittaus

Apache 2 performance boost with varnish & YSlow