擅长:python、mysql、java
<p>这种差异是由于您使用的底层web服务器造成的</p>
<p>一个类比可以是:<code>two cars, same brand, same options, just a different engine, what's the difference?</code></p>
<p>网络服务器并不完全像汽车,但我想你明白我想说的意思了</p>
<p>基本上,<code>gunicorn</code>是一个<code>synchronous</code>web服务器,而<code>uvicorn</code>是一个<code>asynchronous</code>web服务器。由于您使用了<code>fastapi</code>和<code>await</code>关键字,我想您已经知道<code>asyncio</code>/<code>asynchornous programming</code>是什么了</p>
<p>我不知道代码的差异,所以对我的答案持保留态度,但是<code>uvicorn</code>由于<code>asynchronous</code>部分的原因,性能更高。我对时间差异的猜测是,如果您使用<code>async</code>web服务器,它在启动时就已经配置为处理<code>async</code>函数,而如果您使用<code>sync</code>web服务器,它不是,并且为了抽象该部分,会有某种开销</p>
<p>这不是一个正确的答案,但它给了你一个提示,告诉你区别在哪里</p>