express js 急速入门 (express js quick start)

访问量: 818

refer to:  http://expressjs.com/

expressjs 是nodejs 的web/mobile framework.  

$ mkdir test_express

$ cd test_express && npm install express

$ vim test_express.js

var express = require('express')
var app = express()

app.get('/', function (req, res) {
  res.send('Hello World')
})

app.listen(3000)

$ node test_express.js  (此时 express server 就开始监听3000端口了)

$ curl http://localhost:3000/    # => Hello World 

使用 apache  benchmark 测试下性能:  

ab -n 1000 -c 1000 http://localhost:3000/
Concurrency Level:      1000
Time taken for tests:   0.547 seconds
Complete requests:      1000
Failed requests:        0
Total transferred:      191000 bytes
HTML transferred:       11000 bytes
Requests per second:    1826.48 [#/sec] (mean)  # 这里最好 2216 
Time per request:       547.500 [ms] (mean)
Time per request:       0.547 [ms] (mean, across all concurrent requests)
Transfer rate:          340.68 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   10  11.4      7      30
Processing:    12  105  62.4     82     249
Waiting:       12  105  62.4     82     249
Total:         42  115  62.3    109     249

可以看出, 每秒 1826 ~ 2216 个请求.

订阅/RSS Feed

Subscribe

分类/category