golang vs dlang vs nodejs vs php 性能对比较量

前端之家收集整理的这篇文章主要介绍了golang vs dlang vs nodejs vs php 性能对比较量前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

这是我本机开的一个单核1G内存的Hyper-V虚拟机,首先我们使用的语言和框架版本给大家看一下:

root@kerisy:/home/zoujiaqing#goversion
goversiongo1.5.1linux/amd64
root@kerisy:/home/zoujiaqing#ldc2--version
LDC-theLLVMDcompiler(0.15.0):
basedonDMDv2.066.1andLLVM3.5.0
Defaulttarget:x86_64-pc-linux-gnu
Hostcpu:core-avx2
http://dlang.org-http://wiki.dlang.org/LDC

RegisteredTargets:
aarch64-AArch64(littleendian)
aarch64_be-AArch64(bigendian)
arm-ARM
arm64-AArch64(littleendian)
arm64_be-AArch64(bigendian)
armeb-ARM(bigendian)
cpp-C++backend
hexagon-Hexagon
mips-Mips
mips64-Mips64[experimental]
mips64el-Mips64el[experimental]
mipsel-Mipsel
msp430-MSP430[experimental]
nvptx-NVIDIAPTX32-bit
nvptx64-NVIDIAPTX64-bit
ppc32-PowerPC32
ppc64-PowerPC64
ppc64le-PowerPC64LE
r600-AMDGPUsHD2XXX-HD6XXX
sparc-Sparc
sparcv9-SparcV9
systemz-SystemZ
thumb-Thumb
thumbeb-Thumb(bigendian)
x86-32-bitX86:Pentium-Proandabove
x86-64-64-bitX86:EM64TandAMD64
xcore-XCore
root@kerisy:/home/zoujiaqing#nodejs
nodejs
root@kerisy:/home/zoujiaqing#nodejs--version
v4.2.2
root@kerisy:/home/zoujiaqing#PHP--version
PHP5.6.14-1(cli)
Copyright(c)1997-2015ThePHPGroup
ZendEnginev2.6.0,Copyright(c)1998-2015ZendTechnologies
withZendOPcachev7.0.6-dev,Copyright(c)1999-2015,byZendTechnologies


可以看到对应的版本:

golang: 1.5.1

dlang(ldc2): 2.066.1

nodejs: 4.2.2

PHP: 4.6.14


golang代码

packagemain

import(
"io"
"net/http"
"log"
)
funcHelloServer(whttp.ResponseWriter,req*http.Request){
io.WriteString(w,"hello,world!\n")
}
funcmain(){
http.HandleFunc("/hello",HelloServer)
err:=http.ListenAndServe(":1234",nil)
iferr!=nil{
log.Fatal("ListenAndServe:",err)
}
}

dlang代码

importstd.stdio;

importkerisy.http.server;
importkerisy.utils;
importkerisy.net;

intmain(string[]args)
{
	Addressaddress=Address("0.0.0.0",9999);

	HTTPServerserver=newHTTPServer;
	server.listen(address);

	return0;
}

nodejs代码

varhttp=require('http');
varurl=require('url');

http.createServer(function(req,res){
  varpath=url.parse(req.url).pathname;
vardt=newDate();
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/envPHP
<?PHP

require__DIR__.'/vendor/autoload.PHP';

$app=require_once__DIR__.'/application/bootstrap.PHP';

$status=$app->handleConsole(
newSymfony\Component\Console\Input\ArgvInput,newSymfony\Component\Console\Output\ConsoleOutput
);

exit($status);


运行结果如下:

root@kerisy:/home/zoujiaqing#ab-n10000-c1000http://127.0.0.1:9999/
ThisisApacheBench,Version2.3<$Revision:1706008$>
Copyright1996AdamTwiss,ZeusTechnologyLtd,http://www.zeustech.net/
LicensedtoTheApacheSoftwareFoundation,http://www.apache.org/

Benchmarking127.0.0.1(bepatient)
Completed1000requests
Completed2000requests
Completed3000requests
Completed4000requests
Completed5000requests
Completed6000requests
Completed7000requests
Completed8000requests
Completed9000requests
Completed10000requests
Finished10000requests


ServerSoftware:
ServerHostname:127.0.0.1
ServerPort:9999

DocumentPath:/
DocumentLength:15bytes

ConcurrencyLevel:1000
TiMetakenfortests:0.760seconds
Completerequests:10000
Failedrequests:0
Totaltransferred:1170000bytes
HTMLtransferred:150000bytes
Requestspersecond:13152.77[#/sec](mean)
Timeperrequest:76.030[ms](mean)
Timeperrequest:0.076[ms](mean,acrossallconcurrentrequests)
Transferrate:1502.81[Kbytes/sec]received

ConnectionTimes(ms)
minmean[+/-sd]medianmax
Connect:025.0125
Processing:2126.910215
Waiting:2106.59213
Total:3159.911217

Percentageoftherequestsservedwithinacertaintime(ms)
50%11
66%14
75%17
80%19
90%23
95%42
98%45
99%48
100%217(longestrequest)
root@kerisy:/home/zoujiaqing#ab-n10000-c1000http://127.0.0.1:1234/
ThisisApacheBench,http://www.apache.org/

Benchmarking127.0.0.1(bepatient)
Completed1000requests
Completed2000requests
Completed3000requests
Completed4000requests
Completed5000requests
Completed6000requests
Completed7000requests
Completed8000requests
Completed9000requests
Completed10000requests
Finished10000requests


ServerSoftware:
ServerHostname:127.0.0.1
ServerPort:1234

DocumentPath:/
DocumentLength:19bytes

ConcurrencyLevel:1000
TiMetakenfortests:1.039seconds
Completerequests:10000
Failedrequests:0
Non-2xxresponses:10000
Totaltransferred:1760000bytes
HTMLtransferred:190000bytes
Requestspersecond:9622.04[#/sec](mean)
Timeperrequest:103.928[ms](mean)
Timeperrequest:0.104[ms](mean,acrossallconcurrentrequests)
Transferrate:1653.79[Kbytes/sec]received

ConnectionTimes(ms)
minmean[+/-sd]medianmax
Connect:01817.61650
Processing:02818.424217
Waiting:02213.319217
Total:04633.646217

Percentageoftherequestsservedwithinacertaintime(ms)
50%46
66%60
75%75
80%84
90%95
95%99
98%112
99%117
100%217(longestrequest)
root@kerisy:/home/zoujiaqing#ab-n10000-c1000http://127.0.0.1:8888/
ThisisApacheBench,http://www.apache.org/

Benchmarking127.0.0.1(bepatient)
Completed1000requests
Completed2000requests
Completed3000requests
Completed4000requests
Completed5000requests
Completed6000requests
Completed7000requests
Completed8000requests
Completed9000requests
Completed10000requests
Finished10000requests


ServerSoftware:
ServerHostname:127.0.0.1
ServerPort:8888

DocumentPath:/
DocumentLength:28bytes

ConcurrencyLevel:1000
TiMetakenfortests:1.827seconds
Completerequests:10000
Failedrequests:0
Totaltransferred:1290000bytes
HTMLtransferred:280000bytes
Requestspersecond:5474.02[#/sec](mean)
Timeperrequest:182.681[ms](mean)
Timeperrequest:0.183[ms](mean,acrossallconcurrentrequests)
Transferrate:689.60[Kbytes/sec]received

ConnectionTimes(ms)
minmean[+/-sd]medianmax
Connect:013113.40998
Processing:122430.820428
Waiting:122430.820428
Total:1238136.7201425

Percentageoftherequestsservedwithinacertaintime(ms)
50%20
66%22
75%24
80%25
90%28
95%32
98%61
99%1026
100%1425(longestrequest)
root@kerisy:/home/zoujiaqing#ab-n10000-c1000http://127.0.0.1:8080/
ThisisApacheBench,http://www.apache.org/

Benchmarking127.0.0.1(bepatient)
Completed1000requests
Completed2000requests
Completed3000requests
Completed4000requests
Completed5000requests
Completed6000requests
Completed7000requests
Completed8000requests
Completed9000requests
Completed10000requests
Finished10000requests


ServerSoftware:swoole-http-server
ServerHostname:127.0.0.1
ServerPort:8080

DocumentPath:/
DocumentLength:12bytes

ConcurrencyLevel:1000
TiMetakenfortests:1.466seconds
Completerequests:10000
Failedrequests:0
Totaltransferred:1600000bytes
HTMLtransferred:120000bytes
Requestspersecond:6819.48[#/sec](mean)
Timeperrequest:146.639[ms](mean)
Timeperrequest:0.147[ms](mean,acrossallconcurrentrequests)
Transferrate:1065.54[Kbytes/sec]received

ConnectionTimes(ms)
minmean[+/-sd]medianmax
Connect:235911.56089
Processing:248423.379156
Waiting:206015.259110
Total:8214324.4139207

Percentageoftherequestsservedwithinacertaintime(ms)
50%139
66%150
75%155
80%160
90%174
95%191
98%204
99%205
100%207(longestrequest)

按照这个ab测试结果来看性能最差的是nodejs,最好的是dlang的框架,其次是golang的http模块,PHP的worker框架性能还是可以的,相信PHP7出来以后还能有很多提升。

golang: 9622 qps

dlang: 13152 qps

nodejs: 5474 qps

PHP: 6819 qps

原文链接:/go/190104.html

猜你在找的Go相关文章