2019年,Golang开始吊打Java性能了!!!
最近要同事debug性能,不经意间发现现在Golang性能开始吊打Java了!!!感觉Go发展神速!! 之前Go和Java基本是平手,甚至还有较大差距,请见https://www.cnblogs.com/sunsky303/p/6506663.html。借此机会对比了下,Java/Go http server最近的性能,毕竟这是后端同学最关心的问题之一!!
java 10 vs Golang1.12, Google上最快的2个http server性能PK, 压测10次,取平均值。
Java
import org.rapidoid.buffer.Buf;
import org.rapidoid.http.AbstractHttpServer;
import org.rapidoid.http.HttpStatus;
import org.rapidoid.http.MediaType;
import org.rapidoid.net.abstracts.Channel;
import org.rapidoid.net.impl.RapidoidHelper; public class RapidoidHttpFast extends AbstractHttpServer
{
private static final int port = ;
private static final byte HOME[] = "/".getBytes();
private static final byte HELLO_WORLD[] = "Hello World".getBytes(); @Override
protected HttpStatus handle(Channel ctx, Buf buf, RapidoidHelper req)
{
if (req.isGet.value && matches(buf, req.path, HOME))
{
return ok(ctx, req.isKeepAlive.value, HELLO_WORLD, MediaType.TEXT_PLAIN);
} return HttpStatus.NOT_FOUND;
} public static void main(String[] args) throws Exception
{
new RapidoidHttpFast().listen(port);
}
}
sysctl -n machdep.cpu.brand_string ;java --version ;java -cp ".:/Users/wuqj/Downloads/jar_files/*" HelloWorldExample
Intel(R) Core(TM) i5-4278U CPU @ 2.60GHz
java 10 2018-03-20
Java(TM) SE Runtime Environment 18.3 (build 10+46)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10+46, mixed mode)
19:50:33.353 [main] INFO o.r.config.RapidoidInitializer - Starting Rapidoid v5.5.5, built on 2018-05-27 15:45 UTC
19:50:33.358 [main] INFO o.r.config.RapidoidInitializer - System info | os = Mac OS X | java = 10 | process = 17435@sun-pro.local | max memory = 2048 MB | dir = /labs/java
19:50:33.639 [main] INFO org.rapidoid.env.Environment - No profiles were specified, activating 'default' profile
19:50:33.645 [main] INFO org.rapidoid.env.Environment - No production/dev/test mode was configured, inferring mode | mode = DEV
19:50:33.645 [main] INFO org.rapidoid.env.Environment - Initialized environment | mode = DEV | profiles = [default, dev]
19:50:33.932 [main] INFO org.rapidoid.config.ConfigImpl - Loaded configuration | namespace = config | files = [built-in-config.yml, built-in-config-default.yml, built-in-config-dev.yml]
19:50:34.065 [main] INFO o.rapidoid.http.impl.HttpRoutesImpl - GET / | setup = main | roles = [] | transaction = NONE | mvc = false | cacheTTL = 0
19:50:34.072 [main] INFO org.rapidoid.setup.App - Inferred application root | main = HelloWorldExample | package =
19:50:34.080 [main] INFO org.rapidoid.setup.WatchForChanges - Watching classpath for changes... | classpath = [/labs/java/.]
19:50:34.175 [server] INFO o.r.net.impl.RapidoidServerLoop - Starting server | address = 0.0.0.0 | port = 8080 | I/O workers = 4 | sync = true | accept = non-blocking
19:50:34.399 [main] INFO org.rapidoid.setup.Setup - Server has started | setup = main | home = http://localhost:8080
19:50:34.400 [main] INFO org.rapidoid.setup.Setup - Static resources will be served from the following locations | setup = main | locations = [static, default/static]
ab -c100 -n100000 -k 'http://127.0.0.1:8080/'
This is ApacheBench, Version 2.3 <$Revision: $>
Copyright 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 requests
Completed requests
Completed requests
Completed requests
Completed requests
Completed requests
Completed requests
Completed requests
Completed requests
Completed requests
Finished requests Server Software: Rapidoid
Server Hostname: 127.0.0.1
Server Port: Document Path: /
Document Length: bytes Concurrency Level:
Time taken for tests: 2.872 seconds
Complete requests:
Failed requests:
Keep-Alive requests:
Total transferred: bytes
HTML transferred: bytes
Requests per second: 34822.08 [#/sec] (mean)
Time per request: 2.872 [ms] (mean)
Time per request: 0.029 [ms] (mean, across all concurrent requests)
Transfer rate: 5781.01 [Kbytes/sec] received Connection Times (ms)
min mean[+/-sd] median max
Connect: 0.2
Processing: 1.6
Waiting: 1.6
Total: 1.6 Percentage of the requests served within a certain time (ms)
%
%
%
%
%
%
%
%
% (longest request)
Golang
package main import (
"flag"
"fmt"
"github.com/valyala/fasthttp"
"log"
) var (
addr = flag.String("addr", ":8080", "TCP address to listen to")
compress = flag.Bool("compress", false, "Whether to enable transparent response compression")
) func main() {
flag.Parse()
h := requestHandler if err := fasthttp.ListenAndServe(*addr, h); err != nil {
log.Fatalf("Error in ListenAndServe: %s", err)
}
} func requestHandler(ctx *fasthttp.RequestCtx) {
fmt.Fprintf(ctx, "Hello world")
}
sysctl -n machdep.cpu.brand_string ;go version ; go run ../fasthttp/helloworldserver.go
Intel(R) Core(TM) i5-4278U CPU @ .60GHz
go version go1.12.4 darwin/amd64
ab -c100 -n100000 -k 'http://127.0.0.1:8080/'
This is ApacheBench, Version 2.3 <$Revision: $>
Copyright 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 requests
Completed requests
Completed requests
Completed requests
Completed requests
Completed requests
Completed requests
Completed requests
Completed requests
Completed requests
Finished requests Server Software: fasthttp
Server Hostname: 127.0.0.1
Server Port: Document Path: /
Document Length: bytes Concurrency Level:
Time taken for tests: 2.282 seconds
Complete requests:
Failed requests:
Keep-Alive requests:
Total transferred: bytes
HTML transferred: bytes
Requests per second: 43819.46 [#/sec] (mean)
Time per request: 2.282 [ms] (mean)
Time per request: 0.023 [ms] (mean, across all concurrent requests)
Transfer rate: 7274.72 [Kbytes/sec] received Connection Times (ms)
min mean[+/-sd] median max
Connect: 0.1
Processing: 1.8
Waiting: 1.8
Total: 1.8 Percentage of the requests served within a certain time (ms)
%
%
%
%
%
%
%
%
% (longest request)
QPS上 Go 43819.46吊打 Java 34822.08!!!
看来走Golang路线没错。 后续我有空会分析下原理。
2019年,Golang开始吊打Java性能了!!!的更多相关文章
- Java性能调优攻略全分享,5步搞定!(附超全技能图谱)
对于很多研发人员来说,Java 性能调优都是很头疼的问题,为什么这么说?如今,一个简单的系统就囊括了应用程序.数据库.容器.操作系统.网络等技术,线上一旦出现性能问题,就可能要你协调多方面组件去进行优 ...
- [Golang]字符串拼接方式的性能分析
本文100%由本人(Haoxiang Ma)原创,如需转载请注明出处. 本文写于2019/02/16,基于Go 1.11.至于其他版本的Go SDK,如有出入请自行查阅其他资料. Overview 写 ...
- Java 性能分析工具 , 第 3 部分: Java Mission Control
引言 本文为 Java 性能分析工具系列文章第三篇,这里将介绍如何使用 Java 任务控制器 Java Mission Control 深入分析 Java 应用程序的性能,为程序开发人员在使用 Jav ...
- Java 性能分析工具 , 第 2 部分:Java 内置监控工具
引言 本文为 Java 性能分析工具系列文章第二篇,第一篇:操作系统工具.在本文中将介绍如何使用 Java 内置监控工具更加深入的了解 Java 应用程序和 JVM 本身.在 JDK 中有许多内置的工 ...
- Java 性能优化之 String 篇
原文:http://www.ibm.com/developerworks/cn/java/j-lo-optmizestring/ Java 性能优化之 String 篇 String 方法用于文本分析 ...
- 【转发】关于Java性能的9个谬论
转载请注明出处,感谢大家的支持!本文来自优优码:http://www.uucode.net/201502/9%e4%b8%aa%e8%b0%ac%e8%ae%ba Java的性能有某种黑魔法之称.部分 ...
- java 性能优化(代码优化)
参考博文: java 性能优化:35 个小细节,让你提升 java 代码的运行效率
- 读书笔记系列之java性能优化权威指南 一 第一章
主题:java性能优化权威指南 pdf 版本:英文版 Java Performance Tuning 忽略:(0~24页)Performance+Acknowledge 1.Strategies, A ...
- 浅谈java性能分析
浅谈java性能分析,效能分析 在老师强烈的要求下做了效能分析,对上次写过的词频统计的程序进行分析以及改进. 对于效能分析:我个人很浅显的认为就是程序的运行效率,代码的执行效率等等. java做性能测 ...
随机推荐
- Django ajax 检测用户名是否已被注册
添加一个 register.html 页面 <!DOCTYPE html> <html lang="en"> <head> <meta c ...
- itextpdf5操作表格
下面是一些对表格排版的常用方法,是在制作pdf的时候通过查看ipa和一些博客积累下来的. 包括,表格的宽度,对齐方式,表的页眉页脚,前后间距,padding: 单元格对齐方式,线条设置,段落于单元格之 ...
- Java八大排序之希尔(Shell)排序
希尔排序(Shell's Sort)是插入排序的一种又称“缩小增量排序”(Diminishing Increment Sort),是直接插入排序算法的一种更高效的改进版本.希尔排序是非稳定排序算法.该 ...
- 201871010131-张兴盼《面向对象程序设计(java)》第八周学习总结
项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://www.cnblogs.com/nwnu-daizh/p ...
- Ubuntu下apache2安装配置(内含数字证书配置)
Ubuntu下apache2安装配置(内含数字证书配置)安装命令:sudo apt-get updatesudo apt-get install apache2 配置1.查看apache2安装目录命令 ...
- zz从Word Embedding到Bert模型—自然语言处理中的预训练技术发展史
从Word Embedding到Bert模型—自然语言处理中的预训练技术发展史 Bert最近很火,应该是最近最火爆的AI进展,网上的评价很高,那么Bert值得这么高的评价吗?我个人判断是值得.那为什么 ...
- zzL4自动驾驶中感知系统遇到的挑战及解决方案
本次分享的大纲: Perception Introduction Sensor Setup & Sensor Fusion Perception Onboard System Percepti ...
- window.open()与window.showModuleDialog()
一.window.showModalDialog() 模态对话框. (只支持IE浏览器)window.showModelessDialog() 非模态对话框. 基本语法:vReturnVa ...
- 在WEB显示实时视频流
转载自:https://www.jianshu.com/p/7ef5490fbef7 安装摄像头 这里使用的是树莓派的官方摄像头,使用普通的 USB 摄像头也可以,但前提是你能够搞的定它的驱动. 大概 ...
- jQuery的animate()方法做一个颜色的渐变
需求:在1秒内,由一个颜色变到另一个颜色,不是1秒后再变色. <!DOCTYPE html> <html lang="en"> <head> & ...