Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"iter" example does not work as expected #14

Closed
defnull opened this issue Jul 26, 2010 · 1 comment
Closed

"iter" example does not work as expected #14

defnull opened this issue Jul 26, 2010 · 1 comment

Comments

@defnull
Copy link

defnull commented Jul 26, 2010

The iter-example basically looks like this:

def application(environ, start_response):
    start_response('404 Not Found', [('Content-type', 'text/plain')])
    yield 'Pong!'
    time.sleep(5)
    yield "and"
    time.sleep(5)
    yield "Ping!!!"

The example implies that you can defer parts of the response and the server processes other requests in the meantime. This is how I understand asynchrony: To not wait for blocking calls but do useful stuff in the meantime.

A quick test shows that fapws3 blocks completely instead of handling the requests in parallel:

$ ab -n10 -c10 http://0.0.0.0:8080/
Concurrency Level:      10
Time taken for tests:   100.066 seconds
Complete requests:      10
Time per request:       100065.744 [ms] (mean)

10 concurrent requests took 100 seconds. That is an actual concurrency of exactly one :( The time.sleep() call blocks the entire server, which is no surprise if you look at it. sleep() (as any other blocking API) blocks the thread it is called in and fapws3 only utilises the main-thread. If an application blocks, the libev event-loop blocks too.

I think this should be documented. Fapws3 is asynchronous at network-side but totally synchronous at application-side. Ajax with long polling (for example) is not possible with fapws3.

By the way: This actually works with thread-based servers (until the worker thread-pool is exhausted that is).

@william-os4y
Copy link
Owner

Thanks for your comment.
You are right, I should clarify it.

But I invite you to look at the lasts release in the master branch, the defer feature is more what ou are looking for.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants