The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Using Apache ab for benchmarking and gnuplot for graphing

Discussion in 'Workarounds and Optimization' started by cPanelTristan, May 8, 2012.

  1. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    Using Apache's ab tool

    The Apache ab (apache benchmark) tool typically comes default with RHEL and CentOS systems. It can be used for benchmarking differences in a website (such as before and after optimizing a page) or changing PHP handlers. You can see if it is installed onto yours using the following command:

    Code:
    whereis ab
    You should see a return such as the following:

    Code:
    # whereis ab
    ab: /usr/bin/ab /usr/share/man/man1/ab.1.gz
    If you do not find it, it's within the httpd-tools package for Apache, so you can remove httpd* from /etc/yum.conf exclude line, then run:

    Code:
    yum install httpd-tools
    Then re-add httpd* to /etc/yum.conf file.

    To run a test on a page or domain, you'd use the following example type of command:

    Code:
    ab -n 1000 -c 20 http://domain.com/
    Please note that -n 1000 represents 1000 requests will be sent to the page, -c 20 represents 20 concurrent connections at a time (so 20 the first pass, 20 the second and so on until you have 1000 requests sent), and the domain is replaced with http://domain.com/ where the trailing slash (/) is required for the url to be seen as valid by the ab tool.

    Now, if you want to keep a record of the data, you'll add the -g /path flag such as the following:

    Code:
    ab -n 1000 -c 50 -g /root/apacheab/domain.dat http://domain.com/
    Here I've changed the concurrency level to 50 (-c 50) and added -g /root/apacheab/domain.dat for generating the results to /root/apacheab/domain.dat file. The folder must already exist for the path:

    Code:
    mkdir /root/apacheab
    Installing and using gnuplot with Apache ab tool

    gnuplot is easily installed using yum:

    Code:
    yum install gnuplot
    If you see the following error during the install attempt:

    Simpley edit /etc/yum.conf to remove the perl* exclusion temporarily, re-run the "yum install gnuplot" command, then re-add the perl* entry into the /etc/yum.conf exclude line.

    After installation, you can then create a file to graph the data you've created:

    Code:
    touch /root/apacheab/plot.p
    In the file, put the following:

    Code:
    #output as png image
    set terminal png
    
    #save file to "domain.png"
    set output "domain.png"
    
    #graph title
    set title "ab -n 1000 -c 50"
    
    #nicer aspect ratio for image size
    set size 1,0.7
    
    # y-axis grid
    set grid y
    
    #x-axis label
    set xlabel "request"
    
    #y-axis label
    set ylabel "response time (ms)"
    
    #plot data from "domain.dat" using column 9 with smooth sbezier lines
    #and title of "something" for the given data
    plot "domain.dat" using 9 smooth sbezier with lines title "something"
    Above you would replace the following:
    - domain.png with the actual name of the image you want to create
    - ab -n 1000 -c 50 with the Apache ab tool benchmarking used (while this is just a title, it helps to know what levels were used for the benchmarking)
    - domain.dat with the name of the .dat file created with the -g /path command used when you ran ab
    - something with the actual component being checked

    If you want to compare two different components, you can add a second plot line such as the following:

    Code:
    #plot data from "domain.dat" and "domain2.dat" using column 9 with smooth sbezier lines
    #and titles of "something1" and "something2" for the given data
    plot "domain.dat" using 9 smooth sbezier with lines title "something1", \
     "domain2.dat" using 9 smooth sbezier with lines title "something1"
    Once you have the data in the plot.p file, simply run the following for gnuplot to graph it:

    Code:
    gnuplot /root/apacheab/plot.p
    To see the power of this, I created the following comparison of dso + mod_ruid2 (with RDocumentChRoot) for a default WordPress site I installed, then I switched the server to suPHP. I ran ab on the site with 1000 connections and 50 concurrent connections, and pushed the data to danielle.dat for the dso + mod_ruid2 results and danielle2.dat for the suPHP ones. I then graphed it as danielle2.png file (see the attached image at the end of this post). Here were the commands used for ab and the plot.p file for gnuplot:

    dso + mod_ruid2 ab command
    Code:
    ab -n 1000 -c 50 -g /root/apacheab/danielle.dat http://daniellewallace.com/
    suPHP ab command
    Code:
    ab -n 1000 -c 50 -g /root/apacheab/danielle2.dat http://daniellewallace.com/
    gnuplot /root/apacheab/plot.p contents
    Code:
    #output as png image
    set terminal png
    
    # save file to "danielle2.png"
    set output "danielle2.png"
    
    # graph title
    set title "ab -n 1000 -c 50"
    
    # nicer aspect ratio for image size
    set size 1,0.7
    
    # y-axis grid
    set grid y
    
    # x-axis label
    set xlabel "request"
    
    # y-axis label
    set ylabel "response time (ms)"
    
    # plot data from "danielle.dat" and "danielle2.dat" using column 9 with smooth sbezier lines
    # and titles of "dso + mod_ruid2" and "suphp" for the given data
    plot "danielle.dat" using 9 smooth sbezier with lines title "dso + mod_ruid2", \
     "danielle2.dat" using 9 smooth sbezier with lines title "suphp"
    I then ran this command after saving /root/apacheab/plot.p file:

    Code:
    gnuplot /root/apacheab/plot.p
    This generated an image at /root/apacheab/danielle2.png which I copied to my site:

    Code:
    cp /root/apacheab/danielle2.png /home/danielle/public_html/
    chown danielle:danielle /home/danielle/public_html/danielle2.png
    Of note, you might receive the following message when running the "gnuplot /root/apacheab/plot.p" command:

    Code:
    Could not find/open font when opening font "arial", using internal non-scalable font
    This is because gnuplot looks for TTF fonts at /usr/X11R6/lib/X11/fonts/truetype for fonts. On cPanel, the fonts normally would be placed into /usr/share/fonts for any TTF fonts you have installed (such as arial.ttf). You can always do the following:

    Code:
    mkdir -p /usr/X11R6/lib/X11/fonts/
    ln -s /usr/share/fonts/TTF /usr/X11R6/lib/X11/fonts/truetype
    Then place arial.ttf into /usr/share/fonts/TTF folder.

    danielle2.png

    Enjoy!
     
Loading...

Share This Page