Who is stronger, Java microservice vs go microservice!?

itread01 2021-01-14 20:23:44
stronger java microservice vs microservice

### Preface Java Micro service 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 are no external dependencies ( Like a database ), 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.### Let's take a look at the players on both sides of the challenge arena :- The player in the dark suit is **JAVA**> Java It was acquired by Oracle Sun Microsystems Developed . its 1.0 The version is 1996 Released in , The latest version is 2020 Year of Java15. The main design goal is Java Portability of virtual machines and bit group codes , 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 at 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 many different garbage collection algorithms to speed up its execution .Oracle The lab has recently developed a new Java Virtual machines GraalVM, It has a new compiler and some exciting new features , Such as being able to Java The bit group code is converted into a native image , It can be done without javavm And so on .- And its rivals are young and energetic **GO**> GO It's Robert from Google · Grimmer 、 Rob · Parker and Ken · Thomson built . They're right UNIX、B、C、Plan9、UNIX Windows system has made a great contribution .GO It's open source , stay 2012 The year of 1.0 edition ( Than JAVA late 16 year ), stay 2020 The year of 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 so on . Designed to be the best language for efficient networking and multiprocessing .StackOverflow Yes 27872 A belt “Go” The problem of , and Java Only 1702730 One . This shows that the back waves of the Yangtze River push the front waves .Go It's a static compiler language . It's called goroutines Lightweight programs for ( These are not OS Thread ), There is a unique communication channel between them ( Stylized ,FIFO).Go It's a lot CNCF The preferred language for a project , for example Kubernetes、Istio、Prometheus and Grafana### The comparison before the match is personal ,Go comparison JAVA Say , The advantage lies in :- Go It's easier to achieve composition 、 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 binary file that is statically linked to the machine - There is no virtual machine layer - Binary files have everything you need to run a program , This is for “ From the beginning ” It's very good for the container .- Go Small size 、 Start fast 、 Fast execution ( Right now, yes )- Go No OOP, Inherit , Generic , assertion , Index algorithm - Go Less parentheses in writing - Go There is no loop dependency 、 There are no unused variables or imports 、 There is no coercion for implicit type conversion - Go There's a lot less boilerplate code, but the drawback is :- Go The tool ecosystem is not yet mature , Especially dependency management —— There are several options , None of them is perfect , Especially for non open source development ; There are still compatibility challenges .- Build a new / The code for updated dependencies is very slow ( such as Maven The famous “ Download Internet” The problem is )- Import binds code to the repository , This makes moving code in the repository a nightmare .- Debugging 、 Evaluation is still a challenge - We used indicators - We need to implement some basic algorithms - No dynamic links - There are not many knobs to tune execution or garbage collection 、 Profile execution or optimization algorithm .### The game begins to use JMeter To perform load tests . These tests call these services many times , And collect information about response time 、 throughput ( Transactions per second ) And memory usage . For Go, Collect resident set size ; For Java, Track native memory . Before measuring , Use 1000 Service calls warm up the application . The source code of the application itself and the definition of the load test are all in this GitHub In the repository :https://github.com/markxnelson/go-java-go#### The first round in the first round of testing , In one “ small ” It's been tested on the machine , It's a 2.5GHz Dual core Intel core i7 Laptop ,16GB Memory execution macOS. The test runs 100 A thread , Each thread has 10000 A loop , The rise time is 10 second .Java The application runs in JDK11 and Helidon2.0.1 On . Use Go 1.13.3 Compiled Go Applications . The results are as follows :![file](https://img2020.cnblogs.com/other/626506/202101/626506-20210114155127604-1180639219.png)![file](https://img2020.cnblogs.com/other/626506/202101/626506-20210114155127767-1744939980.png) It can be seen that , The first round is Go Won !JAVA Too much memory ; Yes JVM It has a big impact — We know JVM It's optimized at execution time , So it makes sense on the basis of the first round , What's more, I'll introduce GraalVM Image to make Java The running environment of the application is closer to Go The environment of the application , Added GraalVM Image testing ( use GraalVM EE 20.1.1ー JDK 11 Built native image ) The result is :![file](https://img2020.cnblogs.com/other/626506/202101/626506-20210114155128079-1186522273.png)![file](https://img2020.cnblogs.com/other/626506/202101/626506-20210114155128423-207029454.png) 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](https://img2020.cnblogs.com/other/626506/202101/626506-20210114155129035-1935501481.png)#### The second round in the second round of testing , Use a larger machine to perform the test .36 nucleus ( Each core has two threads )、256GB Memory 、 Execute oraclelinux7.8 The machine . Similar to the first round , Used 100 A thread , Each thread uses 10,000 A loop ,10 Second acceleration time , And the same version Go,Java,Helidon and GraalVM. The results are as follows :![file](https://img2020.cnblogs.com/other/626506/202101/626506-20210114155129423-9183718.png) This round is GraalVM I won ! Here's a response time graph of some tests :![file](https://img2020.cnblogs.com/other/626506/202101/626506-20210114155129867-1575449173.png)![file](https://img2020.cnblogs.com/other/626506/202101/626506-20210114155130342-589987172.png)![file](https://img2020.cnblogs.com/other/626506/202101/626506-20210114155130712-1279765043.png) In this test ,Java The variants perform much better , And in the absence of use Java In the case of logging , It's much more effective than Go.Java It seems to be better able to use the multicore and threads provided by the hardware ( And Go comparison ). The best performance of this round comes from GraalVM native image, The average response time is 0.25 millisecond , The number of transactions per second is 82426 One , and Go The best result is 1.59 Milliseconds and 39227 One tps, However, it costs two orders of magnitude more memory !GraalVM Image ratio in jvm The same application running on is about 30–40%!#### In the third round, this time , The game is in Kubernetes The cluster runs these applications , This is a more natural execution time environment for microservices . This time a Kubernetes 1.16.8 Cluster , It has three working nodes , Each node has two cores ( Each core has two threads )、14GB Of RAM and oraclelinux7.8. Application access is through Traefik The entrance controller does ,JMeter stay Kubernetes Out of cluster execution , For some tests , For other tests , Use ClusterIP And execute JMeter. Just like the previous test , We used 100 A thread , Each thread uses 10,000 A loop , 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 The results are as follows :![file](https://img2020.cnblogs.com/other/626506/202101/626506-20210114155131033-820424159.png) Here's a response time graph of some tests :![file](https://img2020.cnblogs.com/other/626506/202101/626506-20210114155131420-1181988396.png) In this round , We observed Go Sometimes faster ,GraalVM Sometimes images are faster , But the difference between the two is very small ( Usually smaller than 5%).Java Seem to be more than Go Better at using all available cores / Thread — We're in Java Better... In the test CPU utilization .Java Performance is better on machines with more cores and memory ,Go The efficiency is smaller / It's better on a weaker machine . In one “ Production scale ” On the machine ,Java It's easy to talk to her Go Just as fast , Or faster ### Finally, there will be more test competitions , Let's see who's better ! If you are interested, you can try it yourself , Remember to tell us the result ! This article refers to :https://medium.com/helidon/can-java-microservices-be-as-fast-as-go-5ceb9a45d673> Welcome to my public account : Programming apes DD, Get exclusive free learning resources to help you Java The road to learning ! In addition, I give books every week ~

  1. springboot异常处理之404
  2. Spring boot security international multilingual I18N
  3. Spring boot exception handling 404
  4. Netty系列化之Google Protobuf编解码
  5. Netty之编解码
  6. Java编解码
  7. Netty解码器
  8. Netty与TCP粘包拆包
  9. Netty开发入门
  10. Java集合遍历时遇到的坑
  11. Spring IOC 源码解析(下)
  12. Spring IoC源码解析(上)
  13. Google protobuf codec of netty serialization
  14. Encoding and decoding of netty
  15. Java codec
  16. Netty decoder
  17. Netty and TCP packet sticking and unpacking
  18. Introduction to netty development
  19. Problems encountered in Java collection traversal
  20. Spring IOC source code analysis (2)
  21. Spring IOC source code analysis (Part one)
  22. 半小时用Spring Boot注解实现Redis分布式锁
  23. Implementing redis distributed lock with spring boot annotation in half an hour
  24. What should we do if we can't get tickets for Spring Festival transportation? You can solve this problem by using these ticket grabbing apps!
  25. 百度智能(文本识别),API传图OC代码与SDK使用
  26. springboot源码解析-管中窥豹系列之aware(六)
  27. Baidu intelligent (text recognition), API map, OC code and SDK
  28. Spring boot source code analysis
  29. springboot源码解析-管中窥豹系列之aware(六)
  30. 百度智能(文本识别),API传图OC代码与SDK使用
  31. Spring boot source code analysis
  32. Baidu intelligent (text recognition), API map, OC code and SDK
  33. Java学习笔记
  34. Java learning notes
  35. Sentry(v20.12.1) K8S 雲原生架構探索, SENTRY FOR JAVASCRIPT 手動捕獲事件基本用法
  36. 我的程式設計師之路:自學Java篇
  37. SpringBoot專案,如何優雅的把介面引數中的空白值替換為null值?
  38. Sentry (v20.12.1) k8s cloud native architecture exploration, sentry for JavaScript manual capture event basic usage
  39. My way of programmer: self study java
  40. Spring boot project, how to gracefully replace the blank value in the interface argument with null value?
  41. Redis 用的很溜,了解过它用的什么协议吗?
  42. Redis is easy to use. Do you know what protocol it uses?
  43. 《零基础看得懂的C++入门教程 》——(10)面向对象
  44. Introduction to zero basic C + + (10) object oriented
  45. HTTP status code and troubleshooting
  46. Java NIO之Channel(通道)入门
  47. Introduction to Java NiO channel
  48. Spring中的@Valid 和 @Validated注解你用对了吗
  49. Are you using the @ valid and @ validated annotations correctly in spring
  50. Spring中的@Valid 和 @Validated注解你用对了吗
  51. Are you using the @ valid and @ validated annotations correctly in spring
  52. Redis | 慢查询
  53. Redis | slow query
  54. RabbitMQ一个优秀的.NET消息队列框架
  55. Autofac一个优秀的.NET IoC框架
  56. 如何使用Redis实现分布式缓存
  57. Rabbitmq an excellent. Net message queue framework
  58. Autofac is an excellent. Net IOC framework
  59. How to use redis to realize distributed cache
  60. JDK1.7-HashMap原理