Does the bottle request without concurrency?

At first, I think Bottle will handle requests at the same time, so I wrote the test code below:

import json from bottle import Bottle, run, request, response, get, post import time app = Bottle() NUMBERS = 0 @app.get("/test") def test(): id = request.query.get('id', 0) global NUMBERS n = NUMBERS time.sleep(0.2) n += 1 NUMBERS = n return id @app.get("/status") def status(): return json.dumps({"numbers": NUMBERS}) run(app, host='0.0.0.0', port=8000) 

Then I use jmeter to query /test url with 10 loop cycles 20 times.

After that, /status gives me {"numbers": 200} , which seems like the bottle is not processing requests at the same time.

I did not get anything?

UPDATE

I did another test, I think it can prove that the bottle processes requests one by one (without concurrency). I slightly modified the test function:

 @app.get("/test") def test(): t1 = time.time() time.sleep(5) t2 = time.time() return {"t1": t1, "t2": t2} 

And when I access /test twice in the browser, I get:

 { "t2": 1415941221.631711, "t1": 1415941216.631761 } { "t2": 1415941226.643427, "t1": 1415941221.643508 } 
+6
source share
1 answer

Concurrency is not a function of your web infrastructure - it is a function of the web server that you use to maintain it. Since Bottle is WSGI compatible, this means that you can serve Bottle applications through any WSGI server:

  • wsgiref (the link server in stdlib Python) will not give you concurrency.
  • CherryPy sends a thread pool (number of simultaneous requests = number of threads it uses).
  • nginx + uwsgi gives you multiprocessing and multiple threads for each process.
  • Gevent gives you light coroutines, which in your case can easily reach C10K + with very little CPU load (on Linux - on Windows it can only handle 1024 simultaneous open sockets) if your application is mostly IO- or database-rated.

The last two can serve a huge number of simultaneous connections.

According to http://bottlepy.org/docs/dev/api.html , in the absence of specific instructions, bottle.run uses wsgiref to serve your application, which explains why it only processes one request at a time.

+12
source

Source: https://habr.com/ru/post/978171/


All Articles