Skip to content

Instantly share code, notes, and snippets.

@andrewhancox
Created June 25, 2013 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewhancox/5858595 to your computer and use it in GitHub Desktop.
Save andrewhancox/5858595 to your computer and use it in GitHub Desktop.
Speed testing Rackspace Cloudfiles (they're really slow)
import os
import pyrax
import pyrax.exceptions as exc
import shutil
import datetime
import sys
from multiprocessing import Process
import uuid
def get_container():
cdnUserName=""
cdnApiKey=""
containerName=""
pyrax.settings.set('identity_type', 'rackspace')
pyrax.settings.set('region', 'LON')
pyrax.set_credentials(cdnUserName, cdnApiKey)
cf = pyrax.cloudfiles
cont = cf.get_container(containerName)
return cont
def upload_files(cont):
filename = "img.jpg"
for x in range(0,50):
new_fname = str(uuid.uuid4()) + '.jpg'
shutil.copyfile(filename, new_fname)
t1 = datetime.datetime.now()
cont.upload_file(new_fname, content_type="image/jpeg")
t2 = datetime.datetime.now()
os.remove(new_fname)
sys.stdout.write(str(t2-t1))
sys.stdout.write('\n')
sys.stdout.flush()
def do_requests():
cont = get_container()
upload_files(cont)
cont = get_container()
for x in range(0,10):
p = Process(target=upload_files, args=(cont,))
p.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment