web.py is blocked when using multiprocess-lib

140 views Asked by At

It seems to work different. One is very slow and anthor is very fast. Just because [import demo] ? why?

The slow one:

[demo_app.py]

import web
urls = ('/(.*)', 'demo.hello')
app = web.application(urls, globals())
application = app.wsgifunc()
if __name__ == "__main__":
    app.run()

[demo.py]

from multiprocessing import Manager
tmp  = Manager()
class hello:
def GET(self,name):
    return 'Hello world'

[run with uwsgi] uwsgi -d demo.log --http 127.0.0.1:8893 -w demo_app -p 1

[curl http://127.0.0.1: 8893/] is very slow


The OK(fast) one :

[demo_app.py]

import web
import demo
urls = ('/(.*)', 'demo.hello')
app = web.application(urls, globals())
application = app.wsgifunc()
if __name__ == "__main__":
    app.run()

[demo.py]

from multiprocessing import Manager
tmp  = Manager()
class hello:
def GET(self,name):
    return 'Hello world'

[run with uwsgi] uwsgi -d demo.log --http 127.0.0.1:8893 -w demo_app -p 1

[curl is fast

—————————————————————

In the 'slow' one , I strace(linux) the subprocess(uwsgi forked). After uwsgi writing the content, it will epoll_wait 60s. The parameters epoll_event in epoll_wait function is empty. look at the pic below: strace log

1

There are 1 answers

3
pbuck On

With the fast one, you've imported demo on program start (i.e., during uwsgi startup). Therefore, no additional overhead during the HTTP request.

With the slow one, demo is imported on first HTTP request (i.e., during curl). Once it has been loaded times are the same.