Search This Blog

Sunday, July 29, 2012

How to avoid Rackspace cloud API limits when creating cloud servers (cloudservers.exceptions.OverLimit)

The Rackspace Cloud API has number of limitations. One of them is how many cloud server you can create in 1 minute. The current limitations [1] looks like:

VerbURIRegExDefault
POST*.*10/min
POST*/servers^/servers50/
When your program [2] tries to create more than 10 cloud servers a minute you are going to run into error and start seeing this cloudservers.exceptions.OverLimit exception.

$ python performance-single-cs.py -v -t 1 -s 13 -u user -k key  run | tee log.$(date +%s).txt

Traceback (most recent call last):
  File "performance-single-cs.py", line 349, in module
    Main().run()
  File "performance-single-cs.py", line 346, in run
    self.test_performance(user,key, sample, cs_count, timeout)
  File "performance-single-cs.py", line 298, in test_performance
    t.test_multi_cs_perf(sample, cs_count, timeout)
  File "performance-single-cs.py", line 250, in test_multi_cs_perf
    cs_records=self.cs_create_all(cs_count, i+1)
  File "performance-single-cs.py", line 225, in cs_create_all
    server=self.cs_create(k, sample_nr)
  File "performance-single-cs.py", line 178, in cs_create
    server=sm.create(name, image, flavor)
  File "/usr/lib/pymodules/python2.7/cloudservers/servers.py", line 172, in create
    return self._create("/servers", body, "server")
  File "/usr/lib/pymodules/python2.7/cloudservers/base.py", line 26, in _create
    resp, body = self.api.client.post(url, body=body)
  File "/usr/lib/pymodules/python2.7/cloudservers/client.py", line 69, in post
    return self._cs_request(url, 'POST', **kwargs)
  File "/usr/lib/pymodules/python2.7/cloudservers/client.py", line 50, in _cs_request
    resp, body = self.request(self.management_url + url, method, **kwargs)
  File "/usr/lib/pymodules/python2.7/cloudservers/client.py", line 37, in request
    raise exceptions.from_response(resp, body)
cloudservers.exceptions.OverLimit: Too many requests... (HTTP 413)

A naive code that was used in the first version of my program was simply trying to sent as many create requests as possible. This of course is not going to work if we increase servers above the allowed limit.


Code demonstration

An exaple of the naive code.

A code that is more inteligent looks like this.



References
  1. http://docs.rackspace.com/servers/api/v1.0/cs-devguide/content/Rate_Limits-d1e1017.html
  2. https://github.com/rtomaszewski/cloud-performance

No comments:

Post a Comment