Python to measure HTTP and HTTPS performances: best way ???

Discussion in 'Python' started by vincent delft, Nov 12, 2004.

  1. I want to write a script that will monitore the performance of a web
    application delivering HTTP and HTTPS pages.

    I would like to know the best way to do it...

    By reading Python Doc. I've found the following:
    For HTTP:
    def http_monitor(host,url):
    starttts=time.time()
    conn=httplib.HTTPConnection(host)
    conn.request("get","/%s" % url)
    res=conn.getresponse()
    data=res.read()
    return time.time()-starttts
    Where Host and URL concerns an HTTP web page.

    For HTTPS:
    def https_monitor(host,url):
    starttts=time.time()
    conn=httplib.HTTPSConnection(host)
    conn.request("get","/%s" % url)
    res=conn.getresponse()
    data=res.read()
    return time.time()-starttts
    Where Host and URL concerns an HTTPS web page.

    Does this is valid ?
    For HTTPS, I'm not dealing with encryption Key ... is it normal ?

    Thanks.
     
    vincent delft, Nov 12, 2004
    #1
    1. Advertising

  2. HTTPS is usually about 5x slower than HTTP on the exact same web server
    because of the encryption.
    Best to send a mid-sized JPG or PNG and time that.
     
    fuzzylollipop, Nov 13, 2004
    #2
    1. Advertising

  3. Am Fri, 12 Nov 2004 02:40:13 -0800 schrieb vincent delft:

    > I want to write a script that will monitore the performance of a web
    > application delivering HTTP and HTTPS pages.
    >
    > I would like to know the best way to do it...


    Hi,

    I did the same some days ago. Here is my code:
    #!/usr/bin/env python
    # -*- coding: iso-8859-1 -*-


    # Python Imports
    import os
    import sys
    import time
    import base64
    import signal
    import urllib2

    MAX_PROCESSES=40

    URL="https://yourserver/....?var=foo..."

    # HTTP Basic Auth
    USER="..."
    PASSWORD="..."

    def usage():
    print """Usage: %s
    StressTest ...
    """ % (os.path.basename(sys.argv[0]))

    def mache_stress():
    dauer_list=[]
    try:
    while 1:
    request=urllib2.Request(URL)
    base64string=base64.encodestring('%s:%s' % (
    USER, PASSWORD))
    request.add_header("Authorization", "Basic %s" % base64string)
    start=time.time()
    fd=urllib2.urlopen(request)
    fd.read()
    dauer=time.time()-start
    print "%s OK %05.2f" % (os.getpid(),
    dauer)
    dauer_list.append(dauer)
    except KeyboardInterrupt:
    if dauer_list:
    all=0
    for d in dauer_list:
    all+=d
    print "Ende %s %s Requests %05.2f avg." % (
    os.getpid(), len(dauer_list), all/len(dauer_list))
    raise

    def main():
    if len(sys.argv)!=1:
    usage()
    sys.exit(1)

    pids=[]
    try:
    print "Mit CTRL-C beenden."
    print "URL:", URL
    print "Anzahl der Prozesse:", MAX_PROCESSES
    for i in range(MAX_PROCESSES):
    pid=os.fork()
    if not pid:
    # Hier ist das Kind
    mache_stress()
    else:
    pids.append(pid)
    os.waitpid(0, 0)
    except KeyboardInterrupt:
    #for pid in pids:
    # os.kill(pid, signal.SIGINT)
    pass

    if __name__=="__main__":
    main()
     
    Thomas Guettler, Nov 15, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve B.

    Globalization and performances

    Steve B., Aug 18, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    330
  2. Finder

    Performances de l'import

    Finder, Apr 19, 2006, in forum: Java
    Replies:
    1
    Views:
    381
    Monique Y. Mudama
    Apr 19, 2006
  3. Replies:
    6
    Views:
    566
    =?UTF-8?B?QXJuZSBWYWpow7hq?=
    Apr 28, 2007
  4. Bala2508
    Replies:
    28
    Views:
    1,219
    Jim Langston
    Nov 3, 2007
  5. Piggy

    Deployment and Performances

    Piggy, Jan 18, 2010, in forum: ASP .Net
    Replies:
    5
    Views:
    1,512
    Piggy
    Jan 26, 2010
Loading...

Share This Page