Proxy speed and performance test

I want to test a proxy [gateway] service. What would be the simplest script to check the proxy’s IP speed and  performance? See the following script.

import requests, time
max_request_timeout = 30 # value in seconds
total_visits, timeout_exception_amount, too_many_redirects_exception_amount, request_exception_amount =0,0,0,0
url= '' 

proxy= 'XXXXXXXXX:XXXX' # proxy setting is different based on different service
actual_visit , actual_visit_code_200, load_time_sum = 0, 0, 0
for i in range(0,N):
        total_visits += 1
        start = time.time()        
            res = requests.get(url, proxies = {'http': proxy, 'https': proxy}, timeout=max_request_timeout)
            actual_visit +=1
        except requests.exceptions.Timeout as e:
                print "Timeout exception", e
                timeout_exception_amount += 1

        except requests.exceptions.TooManyRedirects as e:
                print "TooManyRedirects exception", e
                too_many_redirects_exception_amount += 1
        except requests.exceptions.RequestException as e:
                print "RequestException exception", e
                request_exception_amount += 1 
        if res and 200 == res.status_code:
                actual_visit_code_200 += 1
                load_time = round(time.time()-start, 2 )
                print 'Unsuccessful request. Response status code:',res.status_code
                load_time = None
        #print total_visits - request_exception_amount
        #print round(100*(total_visits - request_exception_amount)/total_visits, 3)
        print str(i)+'.\n', 'Performance: {}%'\
              .format(round(100*(total_visits - request_exception_amount)/total_visits, 3))
        print 'RequestException amount:', request_exception_amount
        print 'Avg. load time:', round(load_time_sum/actual_visit_code_200, 3)  
print '\n************ Results ***************'
print 'Total visits:', total_visits
print 'Actual visits, no timeout:', actual_visit
print 'Actual visit with status code 200:', actual_visit_code_200
print 'Timeout exception amount:', timeout_exception_amount
print 'Too many redirects exception amount:', too_many_redirects_exception_amount
print 'RequestException amount:', request_exception_amount
print 'Performance: {}%'.format(round(100*(total_visits - request_exception_amount)/total_visits, 3))
print 'Avg. load time:', round(load_time_sum/actual_visit_code_200, 3) 

This script runs in a loop, iterating over url(s) or rotating proxy value if needed. The script accumulates total url visits (total_visits) and also tallies the various exceptions (Timeout, TooManyRedirects and Request exceptions) into corresponding variables.

Note: only Request Exceptions are caused by a proxy server. The other kinds of exceptions are website (resource) specific: Timeout and TooManyRedirects exceptions.
For calculating the performance of a proxy server, I do the following:

print 'Performance: {}%'.format(round(100*(total_visits - request_exception_amount)/total_visits, 3))

Thus I get a proxy server performance value (in most cases close to 100%).

3 replies on “Proxy speed and performance test”

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.