这是我本机开的一个单核1G内存的Hyper-V虚拟机,首先我们使用的语言和框架版本给大家看一下:
root@kerisy:/home/zoujiaqing# go version go version go1.5.1 linux/amd64 root@kerisy:/home/zoujiaqing# ldc2 --version LDC - the LLVM D compiler (0.15.0): based on DMD v2.066.1 and LLVM 3.5.0 Default target: x86_64-pc-linux-gnu Host CPU: core-avx2 http://dlang.org - http://wiki.dlang.org/LDC Registered Targets: aarch64 - AArch64 (little endian) aarch64_be - AArch64 (big endian) arm - ARM arm64 - AArch64 (little endian) arm64_be - AArch64 (big endian) armeb - ARM (big endian) cpp - C++ backend hexagon - Hexagon mips - Mips mips64 - Mips64 [experimental] mips64el - Mips64el [experimental] mipsel - Mipsel msp430 - MSP430 [experimental] nvptx - NVIDIA PTX 32-bit nvptx64 - NVIDIA PTX 64-bit ppc32 - PowerPC 32 ppc64 - PowerPC 64 ppc64le - PowerPC 64 LE r600 - AMD GPUs HD2XXX-HD6XXX sparc - Sparc sparcv9 - Sparc V9 systemz - SystemZ thumb - Thumb thumbeb - Thumb (big endian) x86 - 32-bit X86: Pentium-Pro and above x86-64 - 64-bit X86: EM64T and AMD64 xcore - XCore root@kerisy:/home/zoujiaqing# nodejs nodejs root@kerisy:/home/zoujiaqing# nodejs --version v4.2.2 root@kerisy:/home/zoujiaqing# php --version PHP 5.6.14-1 (cli) Copyright (c) 1997-2015 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
可以看到对应的版本:
golang: 1.5.1
dlang(ldc2): 2.066.1
nodejs: 4.2.2
php: 4.6.14
golang代码:
package main import ( "io" "net/http" "log" ) func HelloServer(w http.ResponseWriter, req *http.Request) { io.WriteString(w, "hello, world!\n") } func main() { http.HandleFunc("/hello", HelloServer) err := http.ListenAndServe(":1234", nil) if err != nil { log.Fatal("ListenAndServe: ", err) } }
dlang代码:
import std.stdio; import kerisy.http.server; import kerisy.utils; import kerisy.net; int main (string[] args) { Address address = Address("0.0.0.0", 9999); HTTPServer server = new HTTPServer; server.listen(address); return 0; }
nodejs代码:
var http = require('http'); var url = require('url'); http.createServer(function (req, res) { var path = url.parse(req.url).pathname; var dt=new Date(); res.writeHead(200, {'Content-Type': 'text/plain'}); res.write("Hello,World ! \n"+dt.getTime()); res.end();}).listen(8888, "127.0.0.1");
php代码:
#! /usr/bin/env php <?php require __DIR__ . '/vendor/autoload.php'; $app = require_once __DIR__ . '/application/bootstrap.php'; $status = $app->handleConsole( new Symfony\Component\Console\Input\ArgvInput, new Symfony\Component\Console\Output\ConsoleOutput ); exit($status);
运行结果如下:
root@kerisy:/home/zoujiaqing# ab -n 10000 -c 1000 http://127.0.0.1:9999/ 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 1000 requests Completed 2000 requests Completed 3000 requests Completed 4000 requests Completed 5000 requests Completed 6000 requests Completed 7000 requests Completed 8000 requests Completed 9000 requests Completed 10000 requests Finished 10000 requests Server Software: Server Hostname: 127.0.0.1 Server Port: 9999 Document Path: / Document Length: 15 bytes Concurrency Level: 1000 Time taken for tests: 0.760 seconds Complete requests: 10000 Failed requests: 0 Total transferred: 1170000 bytes HTML transferred: 150000 bytes Requests per second: 13152.77 [#/sec] (mean) Time per request: 76.030 [ms] (mean) Time per request: 0.076 [ms] (mean, across all concurrent requests) Transfer rate: 1502.81 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 2 5.0 1 25 Processing: 2 12 6.9 10 215 Waiting: 2 10 6.5 9 213 Total: 3 15 9.9 11 217 Percentage of the requests served within a certain time (ms) 50% 11 66% 14 75% 17 80% 19 90% 23 95% 42 98% 45 99% 48 100% 217 (longest request) root@kerisy:/home/zoujiaqing# ab -n 10000 -c 1000 http://127.0.0.1:1234/ 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 1000 requests Completed 2000 requests Completed 3000 requests Completed 4000 requests Completed 5000 requests Completed 6000 requests Completed 7000 requests Completed 8000 requests Completed 9000 requests Completed 10000 requests Finished 10000 requests Server Software: Server Hostname: 127.0.0.1 Server Port: 1234 Document Path: / Document Length: 19 bytes Concurrency Level: 1000 Time taken for tests: 1.039 seconds Complete requests: 10000 Failed requests: 0 Non-2xx responses: 10000 Total transferred: 1760000 bytes HTML transferred: 190000 bytes Requests per second: 9622.04 [#/sec] (mean) Time per request: 103.928 [ms] (mean) Time per request: 0.104 [ms] (mean, across all concurrent requests) Transfer rate: 1653.79 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 18 17.6 16 50 Processing: 0 28 18.4 24 217 Waiting: 0 22 13.3 19 217 Total: 0 46 33.6 46 217 Percentage of the requests served within a certain time (ms) 50% 46 66% 60 75% 75 80% 84 90% 95 95% 99 98% 112 99% 117 100% 217 (longest request) root@kerisy:/home/zoujiaqing# ab -n 10000 -c 1000 http://127.0.0.1:8888/ 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 1000 requests Completed 2000 requests Completed 3000 requests Completed 4000 requests Completed 5000 requests Completed 6000 requests Completed 7000 requests Completed 8000 requests Completed 9000 requests Completed 10000 requests Finished 10000 requests Server Software: Server Hostname: 127.0.0.1 Server Port: 8888 Document Path: / Document Length: 28 bytes Concurrency Level: 1000 Time taken for tests: 1.827 seconds Complete requests: 10000 Failed requests: 0 Total transferred: 1290000 bytes HTML transferred: 280000 bytes Requests per second: 5474.02 [#/sec] (mean) Time per request: 182.681 [ms] (mean) Time per request: 0.183 [ms] (mean, across all concurrent requests) Transfer rate: 689.60 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 13 113.4 0 998 Processing: 12 24 30.8 20 428 Waiting: 12 24 30.8 20 428 Total: 12 38 136.7 20 1425 Percentage of the requests served within a certain time (ms) 50% 20 66% 22 75% 24 80% 25 90% 28 95% 32 98% 61 99% 1026 100% 1425 (longest request) root@kerisy:/home/zoujiaqing# ab -n 10000 -c 1000 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 1000 requests Completed 2000 requests Completed 3000 requests Completed 4000 requests Completed 5000 requests Completed 6000 requests Completed 7000 requests Completed 8000 requests Completed 9000 requests Completed 10000 requests Finished 10000 requests Server Software: swoole-http-server Server Hostname: 127.0.0.1 Server Port: 8080 Document Path: / Document Length: 12 bytes Concurrency Level: 1000 Time taken for tests: 1.466 seconds Complete requests: 10000 Failed requests: 0 Total transferred: 1600000 bytes HTML transferred: 120000 bytes Requests per second: 6819.48 [#/sec] (mean) Time per request: 146.639 [ms] (mean) Time per request: 0.147 [ms] (mean, across all concurrent requests) Transfer rate: 1065.54 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 23 59 11.5 60 89 Processing: 24 84 23.3 79 156 Waiting: 20 60 15.2 59 110 Total: 82 143 24.4 139 207 Percentage of the requests served within a certain time (ms) 50% 139 66% 150 75% 155 80% 160 90% 174 95% 191 98% 204 99% 205 100% 207 (longest request)
按照这个ab测试结果来看性能最差的是nodejs,最好的是dlang的框架,其次是golang的http模块,php的worker框架性能还是可以的,相信php7出来以后还能有很多提升。
golang: 9622 qps
dlang: 13152 qps
nodejs: 5474 qps
php: 6819 qps