flask、tornado、BaseHTTPServer性能简单对比

时间:2023-03-10 07:25:49
flask、tornado、BaseHTTPServer性能简单对比

最近写了一个web应用,分别用flask、tornado、BaseHTTPServer都实现了一次,顺便就对比了一下三者的性能,本结果仅对本次测试负责(这句话很内涵,值得推广)。

测试工具用了ab,时间有限,只测试get方式。

tornado------------------

Concurrency Level: 200
Time taken for tests: 34.444 seconds
Requests per second: 290.33 [#/sec] (mean)
Time per request: 688.872 [ms] (mean)

Concurrency Level: 100
Time taken for tests: 11.845 seconds
Requests per second: 844.27 [#/sec] (mean)
Time per request: 118.445 [ms] (mean)

flask------------------

Concurrency Level: 200
Time taken for tests: 38.146 seconds
Requests per second: 262.15 [#/sec] (mean)
Time per request: 762.923 [ms] (mean)

Concurrency Level: 100
Time taken for tests: 17.919 seconds
Requests per second: 558.08 [#/sec] (mean)
Time per request: 179.186 [ms] (mean)

BaseHTTPServer------------------

性能比前两者差二、三十倍。

结论:没事别用BaseHTTPServer。而tornado和flask各有所长,个人认为写小应用使用tornado更简单,复杂的应用使用flask会好一点。