<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="/xsl/blog.xsl"?>
<!-- Comm..........
....................................................................................
....................................................................................
....................................................................................
....................................................................................
....................................................................................
....................................................................................
....................................................................................
....................................................................................
....................................................................................
....................................................................................
....................................................................................
....................................................................................
....................................................................................
....................................................................................
....................................................................................
....................................................................................
-->
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel> 
<title>Benchmark de pages web dynamiques avec ab / Blog  - tfeserver: Blog de tfe</title> 
<description>html, scripts et tout un tas de trucs...</description> 
<link>http://www.tfeserver.be</link> 
<generator>Perl</generator> 


<item>
    <guid>http://www.tfeserver.be/blog/benchmark_pages_web_dynmiques_ab.xml</guid>
    <link>http://www.tfeserver.be/blog/benchmark_pages_web_dynmiques_ab.xml</link>
    <pubDate>Tue, 22 Mar 2011 19:56:55 GMT</pubDate>
    <title><![CDATA[Benchmark de pages web dynamiques avec ab]]></title>
    <description><![CDATA[<p>
Mini tutorial sous la forme d'un mémo pour benchmarker une page web dynamique (php ou autre) avec l'outil fourni avec le serveur apache: <a href="http://httpd.apache.org/docs/2.0/programs/ab.html">ab</a>.
</p>

<p>Cet outil permets d'envoyer des requêtes en parallèle et mesurer le temps de réponse.</p>

<p>Tout d'abord, si votre page utilise une identification, vous voudrez probablement mesurer les performances de l'utilisateur une fois connecté. Pour cela il faudra passer le cookie d'identification à ab.</p> 
<p>Pour cela, on utilise wget pour récuperer le cookie envoyé:</p>
<pre>$ wget --cookies=on --keep-session-cookies --save-cookies=cookie.txt  http://localhost/mon_url.php</pre>

<p>Par la suite on regarde la valeur du cookie en regardant le contenu du fichier:</p>
<pre>$ cat cookie.txt
# HTTP cookie file.
# Generated by Wget on 2011-03-22 19:58:39.
# Edit at your own risk.

localhost   FALSE   /   FALSE   0   PHPSESSID   aq5fbtj94fshjic8hp04rs8uu0
</pre>
<p>On peut alors utilise cette association clé/valeur dans ab pour simuler le cookie:</p>
<pre>$ ab -c 1 -n 1  -C "PHPSESSID=aq5fbtj94fshjic8hp04rs8uu0" http://localhost/ma_page_Avec_identification.php</pre>

<p>Pour vérifier la bonne identification, il est très util d'avoir un <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html">http error code</a> correct, à savoir un 403 si l'utilisateur n'est pas connecté et un 200 si on a les permissions correctes.</p>
<p>On peut vérifier ce que retourne le serveur à ab en spécifiant un verbose de 4:</p>
<pre>$ ab -v 4 -c 1 -n 1  -C "PHPSESSID=aq5fbtj94fshjic8hp04rs8uu0" http://localhost/ma_page_Avec_identification.php
.... Snip ... 
LOG: Response code = 200
</pre>

<p>Pour finir, sur certaines pages ayant une "protection" (hum hum...) via le header referer, on peut simuler un referer en modifiant l'entête http directement:</p>
<pre> ab -v 4 -c 10 -n 100  -C "PHPSESSID=aq5fbtj94fshjic8hp04rs8uu0" -H "Referer:http://localhost/mapage.php" http://localhost/mapage_avec_Identification.php
</pre>
<p>On en verra alors 10 requêtes simultanées jusqu'à recevoir traiter un total de 100 requêtes.</p>]]></description>
    <author>tfe</author>
    <category>web</category>
</item>


    <item>
        <guid>http://www.tfeserver.be/blog.xml</guid>
        <link>http://www.tfeserver.be/blog.xml</link>
        <pubDate>Wed, 25 Jan 2006 08:22:10 GMT</pubDate>
        <title>Blog</title>
        <description>Blog</description>
        <category>internal</category>
    </item>
    <item>
        <guid>http://www.tfeserver.be/archives.xml</guid>
        <link>http://www.tfeserver.be/archives.xml</link>
        <pubDate>Wed, 25 Jan 2006 08:22:10 GMT</pubDate>
        <title>Archives</title>
        <description>Archives</description>
        <category>internal</category>
    </item>
    <item>
        <guid>http://www.tfeserver.be/download.xml</guid>
        <link>http://www.tfeserver.be/download.xml</link>
        <pubDate>Wed, 25 Jan 2006 08:22:10 GMT</pubDate>
        <title>Download</title>
        <description>Download</description>
        <category>internal</category>
    </item>
    <item>
        <guid>http://www.tfeserver.be/liens.xml</guid>
        <link>http://www.tfeserver.be/liens.xml</link>
        <pubDate>Wed, 25 Jan 2006 08:22:10 GMT</pubDate>
        <title>Liens</title>
        <description>Liens</description>
        <category>internal</category>
    </item>

</channel>

</rss>

