Select a backend framework

Select a backend framework

2018-09-29 THUDM team Eunbi Choi

3 main factors considered
  • effort to learn - documentation, community, programming experience

  • productivity - time and effort to write and maintain code

  • performance - concurrency / requests handled per second

Some good backend frameworks

Nodejs, Go, PHP, Ruby, Django, ASP.NET

2 main candidates
  • Nodejs

  • Go

Comparison (from our team's perspective)
factor12
effort to learnNodejsGo
productivityNodejsGo
performance (concurrency)GoNodejs
  1. effort to learn

    Javascript 是使用者最多的语言,学习资料和函数库等资源很丰富。我们全体组员曾经上过相关课程且做过项目,而只有一个组员用过Go。即使用Go开发后端,前端没准还需要用javascript来做。于是选择nodejs,由于已经熟悉 javascript,在学习框架上将要投入的功夫会少。

  2. productivity

    effort to learn 情况差不多,由于已经熟悉语言和框架,开发程序并管理代码的时间会短。合理使用已有的 library,提升生产力。

  3. performance

    Go是为并发而设计的(比如Goroutine),所以并发能力强并容易实现。除了并发以外Go的总体性能很好。每秒处理 HTTP request 数也最多。

         

 

Decision: Nodejs
  • reason1: 考虑因素1和2。不会在学习新的语言上耽误时间,合理使用已有的 library,提高开发速度。

  • reason2: 考虑因素3 - 邀请处理。我们程序的服务对象为中小规模集体(大学小晚会),同时上线人数最多1000左右,同时发要求数会更少。于是在AWS EC2 micro 上用 Apache ab benchmarking tool 进行了小实验,给 nodejs httpserver 发了并行度为 1000 的 1000 个请求,结果如下。其中

    Requests per second: 671.89 [#/sec] (mean) Time per request: 1.488 [ms] (mean, across all concurrent requests)

    说明 nodejs 对付1000人的请求(而且不同时发)不成问题。

root@ip-172-31-18-87:~/httptest# ab -n 1000 -c 1000 -k http://127.0.0.1:8080/
This is ApacheBench, Version 2.3 <$Revision: 1706008 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:
Server Hostname:       127.0.0.1
Server Port:           8080

Document Path:         /
Document Length:       66321 bytes

Concurrency Level:     1000
Time taken for tests:   1.488 seconds
Complete requests:     1000
Failed requests:       0
Keep-Alive requests:   0
Total transferred:     66568000 bytes
HTML transferred:       66321000 bytes
Requests per second:   671.89 [#/sec] (mean)
Time per request:       1488.337 [ms] (mean)
Time per request:       1.488 [ms] (mean, across all concurrent requests)
Transfer rate:         43678.15 [Kbytes/sec] received

Connection Times (ms)
            min mean[+/-sd] median   max
Connect:       0   29 17.2     32     54
Processing:   23 651 195.4   634     898
Waiting:       17 554 173.3   562     860
Total:         71 680 206.4   674     941

Percentage of the requests served within a certain time (ms)
50%   674
66%   871
75%   875
80%   875
90%   878
95%   879
98%   879
99%   879
100%   941 (longest request)
  • reason3: 考虑因素3 - 并发处理。Go的并发处理很优秀,但是其实用不到它的优点。因为服务器收到用户的请求以后,几乎用不到CPU来计算。所以 singlethreaded event loop 反而会比 multi threaded 代价小,速度快。

Reference

转载于:https://www.cnblogs.com/THUDM/p/9759693.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值