WEB开发框架性能排行与趋势分析2-三大惊喜变化

WEB开发框架性能排行与趋势分析2-三大惊喜变化

Web框架性能排名

上一次基于TechEmpower的《Web Framework Benchmarks》性能基准测试的解读之后,时隔两年此次Round19(2020-05-28)榜单有了三个令人兴奋的变化:

 

WEB开发框架性能排行与趋势分析2-三大惊喜变化

 注:带星号的项目支持完整的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

 

发表评论

评论已关闭。

相关文章