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做性能测 ...
随机推荐
- 简单的基于promise的ajax封装
基于promise的ajax封装 //调用方式: /* ajaxPrmomise({ url:, method:, headers:{} }).then(res=>{}) */ ;(functi ...
- 003-OpenStack-镜像服务
OpenStack-镜像服务 [基于此文章的环境]点我快速打开文章 1.安装和配置 控制节点(controller) 1.1 创库授权 glance mysql CREATE DATABASE gla ...
- 07webpack--下载对应的css模块
<!--本节 loader配置处理css样式 在src下新建css文件夹 在css下创建index.css 在main.js这个入口文件中 引入js模块 和 css杨思表是不同的 在main.j ...
- idea中的插件,可以快速将类中的属性转换成Json字符串
当我们想要测试接口的时候,难免会根据一个类,一个一个的写json数据,当属性比较少时还行,但当属性多的时候就比较麻烦了, 为了解决这个问题,我们可以安装第三方的插件来快速生成json字符串. 步骤如下 ...
- 201871010109-胡欢欢《面向对象程序设计(java)》第6-7周学习总结
实验六 继承定义与使用 实验时间 2019-9-29 第一部分:理论部分. 1.继承:已有类来构建新类的一种机制.档定义了一个新类继承另一个类时,这个新类就继承了这个类的方法和域,同时在新类中添加新的 ...
- 用eclipse开发Android,用Genymotion测试时报错adb发生错误
每当我要运行安卓程序时,控制台就会报出 The connection to adb is down, and a severe error has occured. You must restart ...
- 9.第一个vue-cli项目
1.什么是vue-cli vue-cli 官方提供的一个脚手架,用于快速生成一个 vue 的项目模板; 预先定义好的目录结构及基础代码,就好比咱们在创建 Maven 项目时可以选择创建一个骨架项目,这 ...
- icon发展史速览
icon 发展史 img 多张图片占用多个请求,想办法减少请求,合并图片,image sprite background-position /* 使用background-position来定位图标 ...
- [LeetCode] 879. Profitable Schemes 盈利方案
There are G people in a gang, and a list of various crimes they could commit. The i-th crime generat ...
- 阿里Sentinel控制台源码修改-对接Apollo规则持久化
改造背景 前面我们讲解了如何对接Apollo来持久化限流的规则,对接后可以直接通过Apollo的后台进行规则的修改,推送到各个客户端实时生效. 但还有一个问题就是Sentinel控制台没有对接Apol ...