Java, Scala, and go languages multi-threaded concurrency comparison test results and conclusions

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

See the previous: Java, Scala, and go languages multi-threaded concurrency comparison test. Related code Download: http://qinhui99.itpub.net/resource/2570/31876

Test results and conclusions

Count the number of prime numbers in a 1~n, and record the time spent. The same n, the less time performance the better.

AMD Dual Core 2.8G, 4G memory winxp

Java+conc java+akka1.3java+akka2.0 scala+akka1.3scala+akka2.0 go+ Goroutine

1-n units: Seconds

1000000          0.64          1.14 0.63 Span style= "White-space:pre" >              1.05                       0.65               0.617

2000000          1.71          2.08 1.58 Span style= "White-space:pre" >              2.05                       1.68               1.63

3000000          3.05          3.28 2.79 Span style= "White-space:pre" >              3.3                        2.96               2.91

5000000          6.32          6.18 5.75 Span style= "White-space:pre" >              6.367                     6.1                6.04

10000000        17.14       15.85                 15.8               16.5                       16.6               16.35

12000000 22.4 20.48 20.2 21.32 21.48 21.3

(as AMD hardware platform performance is bad, testing time is long, so only test to 12000000)

Inetl Platform core dual core 2.4G, 4G memory winxp

java+concurrentjava+akka1.3 java+akka2.0scala+ AKKA1.3 scala+ AKKA2.0 Go+goroutine

1-n units: Seconds

1000000      0.209              0.87              0.235              0.73                       0.219               0.28

2000000      0.53              1.12                 0.48                   0.98                       0.485              0.54

5000000      1.93              2.19                 1.55                   2.08                       1.61              1.65

10000000      4.93              4.62              4.09                   4.57                       4.1              4.18

20000000      13.25          11.14               10.95                   11.13              10.92              10.98

30000000 23.24 19.37 19.13 19.25 19.35 19.39


Testing is really a time-consuming and boring thing. After testing on two hardware platforms, there is an Apple system that has no time to test, put it on, and then fill it out later.

Performance test Result Description:

1, in order to be fair, each combination of algorithms are used to pass the parameters to the multi-threaded, avoid using synchronous lock, as far as possible due to the implementation of different languages and affect performance factors.

2.  the best performance before3a distinction is:java+akka2.0,scala+akka2.0,Go+goroutine. It3A combination of multi-threaded concurrency calculation indicators are relatively close. Although before the test, theGothe language reported a great expectation thatGoWould be the winner of the test, but it turns out that on thisCPUmulti-threaded concurrency test case for dense operations,Gonot an advantage, not even betterjava+akka2.0combination. It also proves theAKKAthis high-performance concurrency-computing framework is excellent indeed. Don't knowAKKA2.0friends, please visit:Http://www.gtan.com/akka_doc/index.html.

3. The most common performance isjava+concurrent. When the amount of computation is small, for example,1000000the following time,java+concurrentIt was a good performance. But when the amount of computation is increasing,java+concurrentstarted behaving badly. In the10000000above the time,java+concurrentperformance is even worse. The reason for the bad behavior may be because of the use ofThe Executorservice and future of concurrent. The future is actually a blocking threading pattern, so performance is not optimal. There is time to read the source code of AKKA2.0, perhaps to find some ways to improve the performance of the reference.

4. performance in general isjava+akka1.3and theScala+akka1.3. them andAKKA2.0The biggest difference in versions is that they take a blocking pattern that sends and waits for a return message, andAKKA2.0The version uses a non-blocking mode that is sent regardless. It turns out that blocking mode is much worse than non-blocking mode performance. In addition, althoughAKKA1.3blocking mode performance is not good, but in the case of large computational volume performance is still nice, andGolanguage is similar, thanjava+concurrentbetter.

5. in the Run Java The-server parameter is added to the program . For Scala and go, I don't know how to optimize, so I just use Scala and go normal run commands to start the program. For example,

Java-server Org.aos.concurrent.samples.ConcurrentPrimeFinder 1000000 10 100

Scala com.agiledeveloper.pcj.Primes 1000000 100

test_prime.exe-n=1000000-workers=100

The difficulty degree of programming test results show that:

1. because I have many years of Java programming experience, so java+concurrent A combination is the least time spent coding.

2. for Scala and go languages, I have been studying for about 3 weeks. Due to the interoperability of Scala and the Java platform, as well as the sophistication and ease of use of the Scala platform (development tools and syntax are much better than go), the development of the Scala version takes less time than the go version.

3. Scala+akka1.3thanScala+akka2.0Version is easier to develop. BecauseScala+akka1.3the blocking pattern is easy to understand and the code is small. However, when the congestion mode is relatively large, it is easy to reportTimeoutexception. Need to add aakka.conffile to define a longer blocking wait time. ForScala+akka2.0,AKKAThe official provides a non-blocking model reference example, usingMaster+worker+listenerobject combination. MasterDistribute multiple jobs to more than oneworkerto calculate, workerafter the calculation, the respective calculation results are sent back toMasterto summarize, eventually,MasterSend aggregated results toListenerand outputs the results. In order to use this combination of objects, it causesScala+akka2.0version is more encoded thanScala+akka1.3The version is complex and takes more time. In addition, becauseAKKA2.0There is no blocking mode, so there is no test in the presence of a large amount of computationalTimeoutproblem.

4. from Scala go to Java version, it is really difficult, but fortunately two platforms are interoperable, and there are examples of reference, so it is not too difficult to turn around. As with the Scala version,thejava+akka1.3 version is easier to write than the java+akka2.0 version, and there is a blocking mode Timeout problem.

5,    go language version, due to and Java platform is not interoperable, and the difference is great, coding takes the most time. go language from scala python goroutine In a convenient way to write support for multi-threaded concurrent computing programs, there is really a development prospect. ( used Scala and Go After the language, really annoying Java Inside the lengthy code, especially the damned semicolon ' ; ")

but There are also many flaws in the Go language. Here are a few tests found that the situation:1) language is relatively new, not many people understand. This means that the learning cost and the cost of employing higher;2) development platform is not mature, installed in Windows configuration Go development environment, I experienced very painful. There is a feeling of writing JAVA code with EditPlus, very uncomfortable. 3) strong type conversion, very annoying. In order to use math. Sqrt, actually forced me to write a section from float64 to int code. This has never happened in Java and Scala . To be sure,go so-called compiling fast is actually the programmer himself pay a little more cost to look after the code. 4)Goroutine easy to appear deadlock deadlock phenomenon. There are many reasons for deadlocks, so beginners have headaches.

The final conclusion of the test:

comprehensive performance testing and coding difficulty degree test results, I from the perspective of the project to draw a few conclusions :

1, for Java programmers, if there is no mandatory need, do not need to go to Scala and go language, because java+akka2.0 is good enough to use, Enough to cope with multithreaded high concurrency applications.

2, for Java Programmers, if the program is used in general multithreaded applications, and performance requirements are not high,Java concurrent The package is enough.

3, for Java programmers, if you want to reduce the project's code by half, the learning cost is not too high, performance is also guaranteed,Scala language is a very good choice.

4, for Java Programmers, if the project time is limited, want to use the Go language to implement the project, that basic dead end.

5, for The future of the Go language, perhaps as the Go programming language QQ group Friends said, in the field of cloud computing may be a big shine.

because of the limited capacity, energy and resources, this comparison test is not perfect, there may be a lot of problems. Interested friends are welcome to discuss and express their opinions.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.