<reponame>cgoldberg/corey-projects
#!/usr/bin/env python
#  Copyright (c) 2009 <NAME> (<EMAIL>)
#
#  Single-threaded HTTP Load Generator


import sys
import time
import sys
import http.client


# URL parameters
USE_SSL = False  # HTTPS/SSL support
HOST = 'example.com'
PATH = '/'

INTERVAL = 0  # secs


def main():
    # choose timer to use
    if sys.platform.startswith('win'):
        default_timer = time.clock
    else:
        default_timer = time.time
        
    while True:
        msg = (HOST, PATH)
        start = default_timer()      
        try:
            send(msg)
        except Exception as e:
            print('request failed: ', e)
        finish = default_timer()
        latency = (finish - start)
        expire_time = (INTERVAL - latency)
        print('%.3f' % latency)
        if expire_time > 0:
            time.sleep(expire_time)
                

def send(msg):
    if USE_SSL:
        conn = http.client.HTTPSConnection(msg[0])
    else:
        conn = http.client.HTTPConnection(msg[0])
    try:
        conn.request('GET', msg[1])
        conn.getresponse().read()
    finally:
        conn.close()       


if __name__ == '__main__':
    main()
#!/usr/bin/env python
#  Copyright (c) 2009 <NAME> (<EMAIL>)
#
#  Single-threaded HTTP Load Generator


import sys
import time
import sys
import http.client


# URL parameters
USE_SSL = False  # HTTPS/SSL support
HOST = 'example.com'
PATH = '/'

INTERVAL = 0  # secs


def main():
    # choose timer to use
    if sys.platform.startswith('win'):
        default_timer = time.clock
    else:
        default_timer = time.time
        
    while True:
        msg = (HOST, PATH)
        start = default_timer()      
        try:
            send(msg)
        except Exception as e:
            print('request failed: ', e)
        finish = default_timer()
        latency = (finish - start)
        expire_time = (INTERVAL - latency)
        print('%.3f' % latency)
        if expire_time > 0:
            time.sleep(expire_time)
                

def send(msg):
    if USE_SSL:
        conn = http.client.HTTPSConnection(msg[0])
    else:
        conn = http.client.HTTPConnection(msg[0])
    try:
        conn.request('GET', msg[1])
        conn.getresponse().read()
    finally:
        conn.close()       


if __name__ == '__main__':
    main()
#!/usr/bin/env python #  Copyright (c) 2009 <NAME> (<EMAIL>) # #  Single-threaded HTTP Load Generator # URL parameters # HTTPS/SSL support # secs # choose timer to use