Java Microservices can be like Go Is it as fast as microservice ？
This is a question that I have been thinking about recently .
last year 8 In the the Oracle Groundbreakers Tour 2020 LATAM At the conference ,Mark Nelson and Peter Nagy I've done a series of basic tests to compare . Next, let's introduce .
In the circle of programmers , The general view is Java The old 、 slow 、 boring , and Go yes fast 、 new 、 cool
In order to do a relatively fair test as much as possible , They use a very simple micro service , There is no external dependency （ Like databases ）, The code path is very short （ Just manipulating strings ）, Using a small 、 Lightweight framework （Helidon for Java and Go tool kit for Go）, Tested different versions of Java And different jvm.
A duel between the two
Let's take a look at the players on both sides of the challenge arena first ：
- The player in the dark suit is JAVA
Java It was acquired by Oracle Sun Microsystems Developed . its 1.0 The version is 1996 Published in , The latest version is 2020 Year of Java15. The main design goal is Java Portability of virtual machines and bytecodes , And memory management with garbage collection . It's one of the most popular languages in the world , Develop in an open source environment .
Let's take a look first JAVA The problem of , It is generally believed that its biggest problem is its slow speed , It's so slow that it's no longer reasonable , It's more historic . But over the years ,Java There are a lot of different garbage collection algorithms to speed it up .
Oracle The lab has recently developed a new Java virtual machine GraalVM, It has a new compiler and some exciting new features , For example, to be able to Java Convert bytecode to a native image , It can be done without javavm And so on .
- And its rivals are young and energetic GO
GO It's by Robert of Google · Grimmer 、 Rob · Parker and Ken · Created by Thomson . They are for UNIX、B、C、Plan9、UNIX Window system, etc .GO It's open source. , stay 2012 Years issued 1.0 edition （ Than JAVA late 16 year ）, stay 2020 Years issued 1.15 edition . In terms of adoption , Or in terms of the language and tool ecosystem itself , It's all growing fast .
StackOverflow Yes 27872 Strip “Go” The problem of , and Java Only 1702730 individual . It shows that the waves behind push the waves ahead .
Go Is a statically typed compilation language . It has a name goroutines The lightweight process （ These are not OS Threads ）, There is a unique communication channel between them （ Typed ,FIFO）.Go It's a lot of CNCF Preferred language for the project , for example Kubernetes、Istio、Prometheus and Grafana
Pre match comparison
Personally speaking ,Go comparison JAVA Come on , The advantage is ：
- Go Easier to achieve composite 、 Pure function 、 Constant state and other functional modes .
- Go Early in the life cycle , So it doesn't have the heavy burden of backward compatibility —Go It's still easy to break some restrictions to improve .
- Go Compile into a native statically linked binary - There is no virtual machine layer - Binaries have everything you need to run a program , This is for “ Start from scratch ” It's very good for the container .
- Go Small volume 、 Fast start 、 Fast execution （ Right now, yes ）
- Go No, OOP, Inherit , Generic , Assertion , Pointer algorithm
- Go Less parentheses in writing
- Go There is no circular dependence 、 There are no unused variables or imports 、 There is no coercion for implicit type conversion
- Go Much less boilerplate code
The disadvantage is that ：
- Go The tool ecosystem is not yet mature , Especially dependency management —— There are several options , None of them are perfect , Especially for non open source development ; There are still compatibility challenges .
- Building a new environment / The code for updated dependencies is very slow （ such as Maven The famous “ download Internet” problem ）
- Import binds code to the repository , This makes moving code in the repository a nightmare .
- debugging 、 Evaluation is still a challenge
- With the pointer
- We need to implement some basic algorithms
- There are no dynamic links
- There are not many knobs to tune execution or garbage collection 、 Profile execution or optimization algorithm .
The game begins
Use JMeter To run the load test . These tests call these services many times , And collect information about the response time 、 throughput （ Transactions per second ） And memory usage data . about Go, Collect resident set size ; about Java, Track native memory .
Before the measurement , Use 1000 A service call heats up the application .
The source code of the application itself and the definition of the load test are all in this GitHub Repository ：https://github.com/markxnelson/go-java-go
The first round
In the first round of testing , At one “ small ” Tests were carried out on the machine , Is a 2.5GHz Dual core Intel core i7 laptop ,16GB Memory runs macOS. The test runs 100 Threads , Each thread has 10000 Cycle , The rise time is 10 second .Java The application runs in JDK11 and Helidon2.0.1 On . Use Go 1.13.3 Compilation of Go Applications .
give the result as follows :
It can be seen that , The first round is Go Win. ！
JAVA Too much memory ; Preheat right JVM It has a great influence — We know JVM It is optimized at run time , So it makes sense
On the basis of the first round , What's more GraalVM Image to make Java The execution environment of the application is closer to Go Application environment , Added GraalVM Image testing ( use GraalVM EE 20.1.1ー JDK 11 Built native image ) The result is ：
By using GraalVM Image in JVM Run the application on , We don't see any substantial improvement in throughput or response time , But the memory footprint does get smaller .
Here's a response time graph of some tests :
The second round
In the second round of testing , Run the test on a larger machine .36 nucleus （ Two threads per core ）、256GB Memory 、 function oraclelinux7.8 Machine .
Similar to the first round , Used 100 Threads , Each thread uses 10,000 Cycle ,10 Second acceleration time , And the same version Go,Java,Helidon and GraalVM.
give the result as follows ：
This round is GraalVM The image won ！
Here's a response time graph of some tests :
In this test ,Java The variants perform much better , And it's not in use Java In the case of logging , Its performance is much better than that Go.Java It seems to be more able to use the multi-core and execution thread provided by hardware （ And Go comparison ）.
The best performance of this round comes from GraalVM native image, The average response time is 0.25 millisecond , Transactions per second 82426 individual , and Go The best results are as follows 1.59 Milliseconds and 39227 individual tps, However, it costs two orders of magnitude more memory ！
GraalVM Image ratio in jvm The same application running on is about 30–40%！
The third round
This time, , Competition in Kubernetes Running these applications in a cluster , This is a more natural microservice runtime environment .
This time, one was used Kubernetes 1.16.8 colony , It has three working nodes , Each node has two cores （ Each kernel has two execution threads ）、14GB Of RAM and oraclelinux7.8.
Application access is via Traefik The entrance controller performs the following functions ,JMeter stay Kubernetes Running outside the cluster , For some tests , For other tests , Use ClusterIP And run in the cluster JMeter.
Same as the previous test , We used 100 Threads , Each thread uses 10,000 Cycle , as well as 10 Second acceleration time .
Here are the sizes of the various containers :
- Go 11.6MB 11.6 MB
- Java/Helidon 1.41GB 1.41 GB
- Java/Helidon JLinked 150MB 150mb
- Native image 25.2MB 25.2 MB
give the result as follows ：
Here's a response time graph of some tests :
In this round , We observed that Go Sometimes faster ,GraalVM Images are sometimes faster , But the difference between the two is very small ( Usually less than 5%).
Java Seem to be more than Go Better at using all the available kernels / Threads — We are Java Better results were seen in the tests CPU utilization .Java Performance is better on machines with more cores and memory ,Go The performance is small / It's better on a weaker machine . At one “ Production scale ” On the machine ,Java It's easy to talk to her Go As fast as , Or faster
There's going to be more test games coming up , Let's see who's better ！ If you are interested, you can try it yourself , Remember to tell us the result ！
In this paper, the reference ：https://medium.com/helidon/can-java-microservices-be-as-fast-as-go-5ceb9a45d673
Welcome to my official account. ： Program the ape DD, Get exclusive free learning resources to help you Java Way of learning ！ In addition, I give books every week ～
- java springboot activemq Email and SMS microservice , Solve the domestic and international compatibility problem of international service , Including survey of service providers
java springboot activemq Email and SMS microservice , Solve the domestic and international compatibility problem of international service , Including survey of service providers Email and SMS microservice spring boot Microservices receive json Format parameters Verify that the parameters are correct ...
- Java Fresh e-commerce platform - Overview of microservice Architecture
Java Fresh e-commerce platform - Overview of microservice Architecture The problems of monomer Architecture In the traditional software technology architecture system , Basically, the business functions are concentrated in a single application , Or in a single process . Although modern software architecture theory and design principles have been promoted for many years , But the actual technology has evolved ...
- Java Fresh e-commerce platform - Introduction to microservice and actual combat of service splitting architecture
Java Fresh e-commerce platform - Introduction to microservice and actual combat of service splitting architecture When we first entered the software industry, it was the era of single application , The concept of separation of the front and back ends has not yet become popular , It takes a lot of time to develop “ Powerful ” Of JSP above , At that time SOA It's a new technology ...
- java The road of Architecture -（ Micro service topics ） Preliminary understanding of micro service and Internet nacos Preliminary construction
Historical evolution : We used to be one war package , It contains a lot of code , Anyway, I started working on projects like this , A financial system , I can't remember exactly how many lines of code , Many internal functions , But there's not much that can be used , Large code redundancy , Each deployment is big ...
- java The road of Architecture -（ Micro service topics ）ribbon The basic use of and self realization of internal algorithms
Last return : Last time we mainly talked about it , Our registry nacos Use , Like our namespace . grouping . colony . How to use version etc , What if that's the case ? We now have three user services and three order services , How should we distribute these requests ? All requested ...
- java Framework SpringCloud(1)- Microservices and SpringCloud Introduce
Overview of microservices What is it? Industry leader Martin Fowler This is how to describe micro services : Reference resources [ Microservices (Microservices)- Original author of microservice Martin Flower Blog translation ]. Here are some of the highlights of the above blog ...
- java The road of Architecture -（ Micro service topics ）feign The basic use of and nacos Configuration center
Last return : Last time we said ribbon Basic use of , Including the internal algorithms , Fine grained configuration of algorithms , And how we implement our own algorithms , It's mainly about some basic knowledge , Not yet ribbon You can go back to the last article ...
- 【 turn 】 Why choose Spring Boot As an entry-level micro framework for microservices
This article is for Xu erhu, senior engineer of Puyuan cloud computing, to share in the micro classroom of Puyuan cloud computing architecture design group . If you need to join the R & D and design group of Puyuan new generation digital enterprise cloud platform to participate in the micro classroom . Architecture design and discussion live , Please reply directly to this official account. :" Add group full name company Position ...
- Chris Richardson Micro service translation ： Microservice deployment
Chris Richardson Micro service series translation complete 7 Article links : Introduction to microservice Building the use of microservices API gateway The process communication of constructing microservice architecture Service discovery in microservice architecture Event driven data management for microservices Microservice deployment ( ...
- Chris Richardson Micro service translation ： Service discovery in microservice architecture
Chris Richardson Micro service series translation complete 7 Article links : Introduction to microservice Building the use of microservices API gateway The process communication of constructing microservice architecture Service discovery in microservice architecture ( this paper ) Event driven data management for microservices Micro suit ...
- linux How to install virtual machine WDCP
linux Virtual machine Successful installation WDCP Of 2 A way ( Try the first if you don't succeed 2 individual ) Tools / raw material Xshell Cloud server Method / step 1 First use Xshell Connect to your server 2 Enter the code wget ...
- 13_ServletContext object
[ brief introduction ] ServletContext namely Servlet Context object , This object represents the current web Application environment information , One Web Only one application will be created ServletContext object . Web When the container starts , It will We ...
- newly build maven project Problems encountered
stay m2e After successful installation , Start to create maven project 了 , But the following error occurred : It turned out that by accident, I solved , That's to update m2.respository, Click Update Settings -
- Hadoop And ——HBase matters needing attention
Reprint please indicate the source :http://blog.csdn.net/l1028386804/article/details/46447573 1.HBase(NoSQL) Data model of 1.1 surface (table) save ...
- JDBC There are three ways of batch operation
SQL Batch processing is JDBC Important weapon for performance optimization , There are three uses for batch processing . package lavasoft.jdbctest; import lavasoft.common.DBToolkit; import ...
- MySQL Study 13 - Indexes
One . Introduction to index Two . The function of index 3、 ... and . Common indexes : 3.1 General index 3.2 unique index 3.3 primary key 3.4 Composite index Four . Index terms 5、 ... and . How to use index correctly What is the leftmost prefix ? 6、 ... and . Attention to index ...
- Boolean Type in the EF and MySql Mapping relationship in
MySQL No, Boolean type . This is also a strange phenomenon . example : create table xs ( id int primary key, bl boolean ) In this way, it can be created successfully , But take a look at the table ...
- LeetCode 929 Unique Email Addresses Problem solving report
Subject requirements Every email consists of a local name and a domain name, separated by the @ sign. For example, i ...
- IDEA Can run , But the problem with the red underline cannot resolve method
Can compile through and run instructions SDK The import is correct , But why do we click on every Java There will be a lot of red underscores in the file , And prompt idea cant resolve symbol. The reason is that the original history cache may not be cleared , Lead to some mistakes ...