Closed Atakey closed 2 years ago
To have this and understand the difference we need to understand what is Flask doing?
To have this and understand the difference we need to understand what is Flask doing?
flask test code:
import json
from flask import Flask, jsonify, request
app = Flask(__name__)
def preprocess(data):
return data
def post_process(data):
return data
def predict(data):
return data
@app.post('/post')
def inference():
data = json.loads(request.get_data(as_text=True))
preprocess(data)
predict(data)
preprocess(data)
return jsonify({"code": 200})
if __name__ == '__main__':
app.run(host='0.0.0.0', port=42035, debug=False)
And just run it with python script.py
.
# siege test
siege -c5 -t10s -H "Content-type: application/json" -T "application/json" 'http://xxxxxxxx:42035/post POST {"uris":["7_0.jpg"]}'
{ "transactions": 7837,
"availability": 100.00,
"elapsed_time": 9.50,
"data_transferred": 0.10,
"response_time": 0.01,
"transaction_rate": 824.95,
"throughput": 0.01,
"concurrency": 4.97,
"successful_transactions": 7837,
"failed_transactions": 0,
"longest_transaction": 0.05,
"shortest_transaction": 0.00
}
# curl with time
time curl -X POST http://xxxxxx:42035/post -d '{"uris":["7_0.jpg"]}'
{"code":200}
real 0m0.011s
user 0m0.002s
sys 0m0.002s
The main difference is that in Jina all these Preprocessors are microservices that can be scaled separately and communicate with each other via grpc.
While in your example using Flask you just have 3 functions in memory that do nothing.
So this is the explanation of the difference
The main difference is that in Jina all these Preprocessors are microservices that can be scaled separately and communicate with each other via grpc.
While in your example using Flask you just have 3 functions in memory that do nothing.
So this is the explanation of the difference
One executor one microservice, and it can be easy to scale separately and communicate with each other via grpc. It's a very nice design, I like it.
I found that in the gateway
executor, it cost about 4.5ms, the other executor cost about1~1.5ms in framework. gateway
cost much more time. It means that a flow with one executor would cost at least about 6ms in jina framework. Are there something ways to improve performance of gateway
? Thanks.
Let me give some more context to what Joan is saying, mainly for other users that might come across this issue in the future.
As he says, every Jina Executor is an independent microservice, so its own process or docker container, that communicates with the other microservices over the network. Why would we design our system in that way if a simple Flask app can be faster? Consider a few points:
TFExeccutor
should run on a GPU machine, but there may be no reason for preprocess
to run on an expensive GPU machine. Microservices allow as to make that distinction.So I would say that if you care about any of the things above, then Jina is worth a look for you. If you don't, and all you want to do is expose a super simple, low-traffic, low-robustness webservice, then there are other tools in town!
In order to create a slightly more fair comparison, I tried to replicate a simple microservice architecture in Flask. Let me be clear that I am sure that there are better ways to achieve this with Flask (I'm a n000b), and that I am by no means claiming that Flask is inherently slower than Jina; this is just to show that the benchmarks could also swing the other way.
Here is the code i used:
And this is what I get on my machine in terms of results, using the same commands as @Atakey:
curl:
real 0m0,013s
user 0m0,007s
sys 0m0,000s
siege:
Transactions: 3026 hits
Availability: 100.00 %
Elapsed time: 9.61 secs
Data transferred: 1.95 MB
Response time: 0.02 secs
Transaction rate: 314.88 trans/sec
Throughput: 0.20 MB/sec
Concurrency: 4.98
Successful transactions: 3026
Failed transactions: 0
Longest transaction: 0.05
Shortest transaction: 0.00
curl:
real 0m0,019s
user 0m0,000s
sys 0m0,008s
siege:
Transactions: 1647 hits
Availability: 100.00 %
Elapsed time: 9.46 secs
Data transferred: 0.02 MB
Response time: 0.03 secs
Transaction rate: 174.10 trans/sec
Throughput: 0.00 MB/sec
Concurrency: 4.99
Successful transactions: 1647
Failed transactions: 0
Longest transaction: 0.11
Shortest transaction: 0.01
So ~315qps on Jina vs ~175qps on Flask in my very unscientific testing.
Describe your proposal/problem
When I compare jina's flow with flask, I find that flow is much slower than flask, is there something wrong with the codes? Jina'qps only has about 300 , but flask is more than 1000.
Here is my test code.
Environment
Screenshots