0

I need to share an object between threads in web.py. I'm running a web service that performs a calculation & returns a value. The calculation is done using an object that takes up quite a lot of memory, so I don't want it to be created for each request.

I have a solution that works fine, but doesn't seem to scale:

import web
urls = ('/', 'index')

class index:
  def GET(self):
    ...
    result = web.myObject.DoCalculation()
    return result

if __name__ == "__main__":
  app = web.application(urls, globals())
  web.MyObject = LoadObjectFromFile
  app.run()

web.py automatically opens 10 threads, but this number is fixed, and it's very limiting. Can I change that?

The web.py install guide recommends using flup + a server like LightTPD, or Apache. Can this be done while retaining the shared object feature that I need? Can anyone tell me how?

I installed flup and added "fcgi" as a command line parameter when starting the server. This gave me the desired behaviour in terms of threads (unlimited number), but of course didn't perform any task. An fcgi sever needs to be defined, I think. Can this be fixed without running LightTPD, or Apache?

AviM
  • 99
  • 1
  • 5
  • What property does not scale? Is it slow when testing with lots of requests or do you mean the limit of those 10 serving threads? – mvw Aug 26 '13 at 11:46
  • I had an answer with references to Twisted and Django, but I retracted it after another read of your question, because you might want to do this specific with web.py – mvw Aug 26 '13 at 12:24
  • @mvw Yes, it is the limit of 10 serving threads. My calculation is very quick - less than a millisecond, but it is done on the content of a web page. This page has to first be fetched, and this takes a second or two, so the threads are mostly waiting. I'm not using the power of my machine - I need many more serving threads. I'm not locked into _web.py_; I chose it because it looked simple to handle; I would welcome ideas, thanks. – AviM Aug 28 '13 at 15:30

0 Answers0