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

V

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...

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.
 
F

fuzzylollipop

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.
 
T

Thomas Guettler

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()
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top