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

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

Web框架性能排名

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

 

 注:帶星號的項目支持完整的ORM和模板技術laravel

 

1、神奇的Lithium

C++和Rust都是隻提供編譯期反射的,因此實現ORM的方法有兩種,一種是帶生成器,須要工具和預處理。一種是利用宏和模板技術來生成代碼。
git

Lithium這個項目和其它妖豔賤貨不同,代碼優雅得一塌糊塗,並且性能驚人Lithium(ORM)(RAW)以 59.2%的成績一騎絕塵。雖然使用宏和模板有點燒腦,但仍是值得一看。github

對比Rust的Diesel,僅取得了24%的成績仍是有很大提高空間的。Golang的框架測試代碼中沒有一個帶ORM,是由於Golang的反射機制仍是很慢的,直接拖累了性能。web

  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());
  };

 

2、恐怖的Workerman

PHP一直熱衷於各類用底層代碼來提高性能,可是因爲各類緣由,成果有限。即便異步PHP框架swoole的出現,完全捨棄了PHP的基本機制,使得性能有了極大提高,也沒有引發大的改變,但純PHP實現的異步框架Workerman卻有可能改變這一狀況。使用Workerman的Ubiquity框架居然戰勝了一衆框架勇奪第二名。性能提高几十倍,堪稱恐怖。原來PHP已經足夠優秀,只是打開方式不對。sql

Act(ORM)(Rythm): 28.9%django

Ubiquity(ORM)(PHP):28.1%flask

Actix(Diesel)(HBS): 23.6%api

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
        ]);
    }
}

 

3、意外的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

相關文章
相關標籤/搜索