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做性能测 ...
随机推荐
- SpringBoot的学习一:入门篇
SpringBoot是什么: SpringBoot是Spring项目中的一个子工程,是一个轻量级框架. SpringBoot框架中有两个个非常重要的策略:开箱即用和约定优于配置 一.构建工程 1.开发 ...
- Python从零开始——集合Set
一:Python集合知识概览 二:Python的特性.格式.以及各序列结构对比 三:Python集合set的创建 四:集合常用操作之——添加元素 五:集合常见操作之——删除元素 六:集合常见操作之—— ...
- 006-OpenStack-配仪表盘
OpenStack-配仪表盘 [基于此文章的环境]点我快速打开文章 计算节点安装(compute1) 1.安装 yum install openstack-dashboard -y &> ...
- 2019CCPC网络赛 C - K-th occurrence HDU - 6704(后缀数组+ST表+二分+主席树)
题意 求区间l,r的子串在原串中第k次出现的位置. 链接:https://vjudge.net/contest/322094#problem/C 思路 比赛的时候用后缀自动机写的,TLE到比赛结束. ...
- SDL2学习(二):常用枚举值和函数
1. 高频枚举值或结构体 1.1 SDL_WindowFlags /** * \brief The flags on a window * * \sa SDL_GetWindowFlags() */ ...
- linux(10)uwsgi???
[uwsgi] Django-related settings the base directory (full path) #指定项目的绝对路径的第一层路径!!!!!!!!!!!!!!!!!!!!! ...
- 201871020225-牟星源《面向对象程序设计(java)》第十周学习总结
201871020225-牟星源<面向对象程序设计(java)>第十周学习总结 博文正文开头: 项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu- ...
- appium--连续滑动
TouchAction 在之前说过了滑动swip,那种是两点之间的滑动,比如上滑,左滑等.但实际工作中会遇到一些复杂的场景,如九宫格的滑动等待,这时候就要使用TouchAction,TouchActi ...
- [LeetCode] 889. Construct Binary Tree from Preorder and Postorder Traversal 由先序和后序遍历建立二叉树
Return any binary tree that matches the given preorder and postorder traversals. Values in the trave ...
- dogcom在openwrt上的使用
前提,先配置并运行mentohust(作为802.1x认证) 1,取得编译完成的可执行文件(可先在虚拟机里测试) 2,上传到路由器 3,把dogcom主程序和配置文件放在/etc/storage/do ...