Who is stronger, Java microservice vs go microservice!?

Program description DD 2021-01-14 15:59:04
stronger java microservice vs microservice


Preface

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 .

GO suffer C、Python、JavaScript and C++ And other languages . Designed to be the best language for high performance networks and multiprocessing .

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 :

file

file

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 :

file

file

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 :

file

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 :

file

This round is GraalVM The image won !

Here's a response time graph of some tests :

file

file

file

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 :

file

Here's a response time graph of some tests :

file

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

Last

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 ~

版权声明
本文为[Program description DD]所创,转载请带上原文链接,感谢
https://javamana.com/2021/01/20210114155725957A.html

  1. Centos7 one click installation of JDK1.8 shell script
  2. Mounting of file system in Linux (centos7)
  3. How does serverless deal with the resource supply demand of k8s in the offline scenario
  4. Detailed explanation of HBase basic principle
  5. Spring security oauth2.0 authentication and authorization 4: distributed system authentication and authorization
  6. Redis performance Part 5 redis buffer
  7. JavaScript this keyword
  8. Summary of Java multithreading (3)
  9. Sentry(v20.12.1) K8S 云原生架构探索, SENTRY FOR JAVASCRIPT 手动捕获事件基本用法
  10. Sentry(v20.12.1) K8S 云原生架构探索, SENTRY FOR JAVASCRIPT 手动捕获事件基本用法
  11. (10) Spring from the beginning to the end
  12. Summary of Java multithreading (2)
  13. Spring source notes! From the introduction to the source code, let you really understand the source code
  14. A stormy sunny day
  15. Zookeeper (curator), the implementation of distributed lock
  16. Show the sky! Tencent T4's core Java Dictionary (framework + principle + Notes + map)
  17. Spring boot project, how to gracefully replace the blank value in the interface parameter with null value?
  18. Spring boot project, how to gracefully replace the blank value in the interface parameter with null value?
  19. docker+mysql集群+读写分离+mycat管理+垂直分库+负载均衡
  20. docker+mysql集群+读写分离+mycat管理+垂直分库+负载均衡
  21. To what extent can I go out to work?
  22. Java 使用拦截器无限转发/重定向无限循环/重定向次数过多报错(StackOverflowError) 解决方案
  23. Implementation of rocketmq message sending based on JMeter
  24. How to choose the ticket grabbing app in the Spring Festival? We have measured
  25. Implementation of rocketmq message sending based on JMeter
  26. My programmer's Road: self study java
  27. My programmer's Road: self study java
  28. All in one, one article talks about the use of virtual machine VirtualBox and Linux
  29. All in one, one article talks about the use of virtual machine VirtualBox and Linux
  30. Java 使用拦截器无限转发/重定向无限循环/重定向次数过多报错(StackOverflowError) 解决方案
  31. [Java training project] Java ID number recognition system
  32. How does serverless deal with the resource supply demand of k8s in the offline scenario
  33. Detailed explanation of HBase basic principle
  34. Explain the function of thread pool and how to use it in Java
  35. Kubernetes official java client 8: fluent style
  36. 010_MySQL
  37. Vibrant special purchases for the Spring Festival tiktok section, hundreds of good things to make the year more rich flavor.
  38. 010_MySQL
  39. Of the 4 million docker images, 51% have high-risk vulnerabilities
  40. Rocketmq CPP client visual studio 2019 compilation
  41. Rocketmq CPP client visual studio 2019 compilation
  42. Usage of data custom attribute in jquery
  43. Common decompression in Linux
  44. Upload large files in Java
  45. Sentry (v20.12.1) k8s cloud native architecture exploration, sentry for JavaScript manual capture event basic usage
  46. Sentry (v20.12.1) k8s cloud native architecture exploration, sentry for JavaScript manual capture event basic usage
  47. Docker + MySQL Cluster + read / write separation + MYCAT Management + vertical sub database + load balancing
  48. Docker + MySQL Cluster + read / write separation + MYCAT Management + vertical sub database + load balancing
  49. Java use interceptor infinite forwarding / redirection infinite loop / redirection times too many error (stack overflow error) solution
  50. Java use interceptor infinite forwarding / redirection infinite loop / redirection times too many error (stack overflow error) solution
  51. 010_ MySQL
  52. 010_ MySQL
  53. Fast integration of imsdk and Huawei offline push
  54. 消息队列之RabbitMQ
  55. Rabbitmq of message queue
  56. 初学java进制转换方面补充学习
  57. Learn java base conversion supplementary learning
  58. 了解一下RPC,为何诞生RPC,和HTTP有什么不同?
  59. 了解一下RPC,为何诞生RPC,和HTTP有什么不同?
  60. 初学java进制转换方面补充学习