Categories
Development

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= 'https://ipinfo.io/' 

proxy= 'XXXXXXXXX:XXXX' # proxy setting is different based on different service
actual_visit , actual_visit_code_200, load_time_sum = 0, 0, 0
N=1000
for i in range(0,N):
        total_visits += 1
        start = time.time()        
        try: 
            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
                continue

        except requests.exceptions.TooManyRedirects as e:
                print "TooManyRedirects exception", e
                too_many_redirects_exception_amount += 1
                continue
                
        except requests.exceptions.RequestException as e:
                print "RequestException exception", e
                request_exception_amount += 1 
                continue
        
        if res and 200 == res.status_code:
                actual_visit_code_200 += 1
                load_time = round(time.time()-start, 2 )
                load_time_sum+=load_time
        else:
                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%).

Proxy services test

Here I want to share my testing results of different proxy services.

 Production setupDevelopment setup
1. CodeCode is split & gets minified.No
2. Manifest fileYesYes
3. Pre-cache manifestPre-cache manifest gets generated No
4. Source referencesNoSource map
5. Dev server & Hot reloadNoHot reload at Development server for debug purposes and caching
6. Entry file nameindex.production.phtmlindex.developmet.html
7. Build & debug2 steps build Cached files instead of generated files
8. Build speedSlowMuch faster than in Production mode

Test conditions

  • The test has been conducted for over 1000 requests.
  • Request timeout is 30 seconds.
  • The proxy speed was calculated based on the avg. access time to the web page (https://ipinfo.io) with proxy and the avg. access time without proxy:
    speed = avg_load_time_with_proxy - avg_load_time_without_proxy

2 replies on “Proxy speed and performance test”

Leave a Reply

Your email address will not be published. Required fields are marked *

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