WEB開發框架效能排行與趨勢分析2-三大驚喜變化

windfic發表於2021-01-18

WEB開發框架效能排行與趨勢分析2-三大驚喜變化

Web框架效能排名

上一次基於TechEmpower的《Web Framework Benchmarks》效能基準測試的解讀之後,時隔兩年此次Round19(2020-05-28)榜單有了三個令人興奮的變化:

 

 注:帶星號的專案支援完整的ORM和模板技術

 

一、神奇的Lithium

C++和Rust都是隻提供編譯期反射的,所以實現ORM的方法有兩種,一種是帶生成器,需要工具和預處理。一種是利用巨集和模板技術來生成程式碼。

Lithium這個專案和其它妖豔賤貨不一樣,程式碼優雅得一塌糊塗,而且效能驚人Lithium(ORM)(RAW)以 59.2%的成績一騎絕塵。雖然使用巨集和模板有點燒腦,但還是值得一看。

對比Rust的Diesel,僅取得了24%的成績還是有很大提升空間的。Golang的框架測試程式碼中沒有一個帶ORM,是因為Golang的反射機制還是很慢的,直接拖累了效能。

  auto fortunes = sql_orm_schema(sql_db, "Fortune").fields(
    s::id(s::auto_increment, s::primary_key) = int(),
    s::message = std::string());

  my_api.get("/fortunes") = [&](http_request& request, http_response& response) {
    sql_db.max_async_connections_per_thread_ = fortunes_nconn;

    typedef decltype(fortunes.all_fields()) fortune;
    std::vector<fortune> table;

    {
      auto c = fortunes.connect(request.fiber);
      c.forall([&] (const auto& f) { table.emplace_back(metamap_clone(f)); });
    }
    table.emplace_back(0, "Additional fortune added at request time.");

    std::sort(table.begin(), table.end(),
              [] (const fortune& a, const fortune& b) { return a.message < b.message; });

    li::growing_output_buffer ss;
 
    ss << "<!DOCTYPE html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>";
    for(auto& f : table)
    {
      ss << "<tr><td>" << f.id << "</td><td>";
      escape_html_entities(ss, f.message); 
      ss << "</td></tr>";
    }
    ss << "</table></body></html>";

    response.set_header("Content-Type", "text/html; charset=utf-8");
    response.write(ss.to_string_view());
  };

 

二、恐怖的Workerman

PHP一直熱衷於各種用底層程式碼來提升效能,但是由於各種原因,成果有限。即使非同步PHP框架swoole的出現,徹底捨棄了PHP的基本機制,使得效能有了極大提升,也沒有引起大的改變,但純PHP實現的非同步框架Workerman卻有可能改變這一情況。使用Workerman的Ubiquity框架竟然打敗了一眾框架勇奪第二名。效能提升幾十倍,堪稱恐怖。原來PHP已經足夠優秀,只是開啟方式不對。

Act(ORM)(Rythm): 28.9%

Ubiquity(ORM)(PHP):28.1%

Actix(Diesel)(HBS): 23.6%

AspCore(EF)(ASP): 23.3%

class Fortunes extends \Ubiquity\controllers\SimpleViewController {

    public function initialize() {
        \Ubiquity\cache\CacheManager::startProdFromCtrl();
    }

    public function index() {
        $fortunes = SDAO::getAll(Fortune::class);
        $fortunes[] = new Fortune(0, 'Additional fortune added at request time.');
        \usort($fortunes, function ($left, $right) {
            return $left->message <=> $right->message;
        });
        $this->loadView('Fortunes/index.php', [
            'fortunes' => $fortunes
        ]);
    }
}

 

三、意外的Roda

由於JavaScript使用Node.js的非同步機制,使得JS框架出道即巔峰,其它指令碼語言只有奮起追趕的份。此次PHP打了一個翻身仗,讓JavaScript領先的局面,一下子變得落後一步。

而來自Ruby陣營的變化也讓Ruby有了超過JavaScript的可能,Roda的效能在已經是Python效能一倍的基礎上再翻一倍,在沒有完全使用非同步架構的情況下,有如此成績,讓人不禁有所期待。

指令碼開發的效能排名也從JavaScript>Ruby>Python>>>>>>>>>PHP,變成了PHP>>>Ruby>JavaScript>Python。Python也從感覺良好一下子變成了學渣,沒有了存在感。

  static_get '/fortunes' do |_|
    @fortunes = Fortune.all
    @fortunes << Fortune.new(
      :id=>0,
      :message=>'Additional fortune added at request time.'
    )
    @fortunes.sort_by!(&:message)

    view :fortunes
  end

 

附表

C++

Drogon

排名:Drogon(RAW)(CSP):100%

Drogon(MORM)(CSP):81.6%

倉庫:https://github.com/an-tao/drogon

Lithium

排名:Lithium(ORM)(RAW): 59.2%

倉庫:https://github.com/matt-42/lithium

 

Rust

Actix-web

排名:Actix(RAW)(HBS): 89.5%

Actix(Diesel)(HBS): 23.6%

倉庫:https://github.com/actix/actix-web

May-minihttp

排名:May-minihttp(RAW)(Markup): 70.3%

倉庫:https://github.com/Xudong-Huang/may_minihttp

 

Go

Atreugo

排名:Atreugo(RAW)(QuickT): 53.4%

倉庫:https://github.com/savsgio/atreugo

Gofiber

排名:Gofiber(RAW)(QuickT): 44.5%

倉庫:https://github.com/gofiber/fiber

iris-go

排名:(未知)

倉庫:https://github.com/kataras/iris

 

Java

Vert.x

排名:Vert.x(RAW)(Rocker): 51.2%

倉庫:https://github.com/eclipse-vertx/vert.x

Jooby

排名:Jooby(RAW)(Rocker): 46.1%

倉庫:https://github.com/jooby-project/jooby

ActFramework

排名:Act(ORM)(Rythm): 28.9%

倉庫:https://github.com/actframework/actframework

 

C#

AspCore

排名:AspCore(RAW)(ASP): 42.1%

AspCore(EF)(ASP): 23.3%

 

Crystal

Kemal

排名:Kemal(RAW)(ECR):30.8%

倉庫:https://github.com/kemalcr/kemal

 

Kotlin

http4k

排名:http4k(RAW)(PEB):29.9%

倉庫:https://github.com/http4k/http4k

 

PHP

workerman

排名:workerman(RAW)(PHP): 52.0%

kumbiaphp(RAW)(PHP):36.8%

Ubiquity(ORM)(PHP):28.1%

倉庫:https://github.com/walkor/workerman

https://github.com/KumbiaPHP/KumbiaPHP

https://github.com/phpMv/ubiquity

swoole

排名:swoole(RAW)(PHP): 41.8%

ubiquity(ORM)(PHP):20.7%

Imi(ORM)(PHP):17.9%

倉庫:https://github.com/swoole/swoole-src

https://github.com/phpMv/ubiquity

https://github.com/Yurunsoft/IMI

Laravel

排名:Laravel-swoole(ORM)(PHP): 3.1%

Laravel(ORM)(PHP): 0.8%

倉庫:https://github.com/laravel/laravel/

 

Ruby

Roda

排名:Roda(sequel)(ERB): 7.5%

倉庫:https://github.com/jeremyevans/roda

Sinatra

排名:Sinatra(sequel)(Slim): 5.0%

倉庫:https://github.com/sinatra/sinatra

 

JavaScript

Nestjs

排名:Nestjs(ORM)(HBS): 10.0%

倉庫:https://github.com/nestjs/nest

Koa

排名:Koa(ORM)(HBS): 6.8%

倉庫:https://github.com/koajs/koa

 

Python

Sanic

排名:Sanic(RAW)(Jinja2): 9.6%

倉庫:https://github.com/sanic-org/sanic

Django

排名:Django(ORM)(TMP): 2.2%

倉庫:https://github.com/django/django

Flask

排名:Flask(RAW)(Jinja2): 3.4%

Flask(ORM)(Jinja2): 1.5%

倉庫:https://github.com/pallets/flask

 

相關文章