当前位置:网站首页>Completabilefuture of asynchronous tools for concurrent programming
Completabilefuture of asynchronous tools for concurrent programming
2022-06-25 15:24:00 【Running pig ZC】
Catalog
4: Analysis of other parameters
1: Write in the front
We are java Whether we will encounter the problem of processing large quantities of data in the development of , If there is such a scene , You check ES Or is it DB, Will return you a large number of data , There may be more than 100000 orders of magnitude , Even millions , Then you take the data and do some processing , Operations may include cpu It's a complex operation , File store , But not limited to the above , What to do with that ? Also in the use of for Cycle one by one ? It is estimated that the client will time out , The disgusting thing is that the client has set a timeout , Then pull it again / Many times your ES, Or is it DB, Then at work the next day , The company's network administrator will send you an email , It says “ In the early morning of this morning 3 A little bit later , It lasted about an hour , Something happened on the so and so machine cpu / io It seems a little high , Um. It is very euphemistic to say .” Then it is time to consider optimization , Whether to use thread pool to solve this problem , Or asynchronous .
2: The actual combat
1: Test code address :
https://gitee.com/zccpojo/testcomfuture.git
The following two parameters can be adjusted to simulate

2: The test link
The current test parameters are set to : Number of tasks 2000 individual , The processing time of each task is 10ms
1: Sync :
Spend total time on 20479ms, And get all the results 2000 strip

2: asynchronous :
Spend total time on 457ms, And get all the results 2000 strip

3: Comparative data analysis
It's also dealing with 2000 The article number , But we do it asynchronously , I found that the performance improved 20479ms / 457ms ~ 40 times , What amazing data , Looking at it, I felt a little shivering , However, this is also related to the length of work and the number of tasks , If there are more tasks , The effect will be more amazing .
4: Analysis of other parameters
In the above asynchronous processing mode , We used CompletableFuture, We found that it passed in a thread pool , For information about thread pools, please move to
https://blog.csdn.net/weixin_45191798/article/details/100153524
https://blog.csdn.net/weixin_45191798/article/details/100159321
https://blog.csdn.net/weixin_45191798/article/details/100159830
TIPS: It is best to create a thread pool manually when using a thread pool ( There's a lot of laziness here ), Be sure to manually close the thread pool after using it , Don't ask why , The question is 《 Alibaba Development Manual 》
3: summary
When doing a lot of data processing , You can consider caching , L2 cache , Even client caching and necessary asynchrony , This article introduces the use of asynchronous + Thread pool to process large quantities of data , Yes, it can be reduced RTT, To improve the throughput of the system . The source code analysis will be updated later , It's not too early , It's gone . Those who are interested can communicate together .
边栏推荐
- (translation) json-rpc 2.0 specification (Chinese version)
- 55 specific ways to improve program design (1)
- High precision addition
- Review of arrays and pointers triggered by a topic
- QT file reading -qfile
- C language escape character and its meaning
- The robot is playing an old DOS based game
- AB string interchange
- Brain tree (I)
- Custom structure type
猜你喜欢

QT set process startup and self startup

JSON module dictionary and string conversion

Qcodeeditor - QT based code editor

basic_ String mind map

(2) Relational database

‘make_ unique’ is not a member of ‘std’
![[paper notes] semi supervised object detection (ssod)](/img/18/9fba70e6e4329722d9c6ad51d15724.jpg)
[paper notes] semi supervised object detection (ssod)

Afterword of Parl intensive learning 7-day punch in camp

Use Matplotlib to draw a line chart

Review of arrays and pointers triggered by a topic
随机推荐
55 specific ways to improve program design (2)
2.18 codeforces supplement
5 connection modes of QT signal slot
0706-- replace fields in the use case, such as mobile phone number or ID
QT loading third-party library basic operation
Learning notes on February 18, 2022 (C language)
Character encoding minutes
Sequential programming 1
p1408
Use Matplotlib to draw a line chart
Learning C language today is the first time to learn C language. In college, C linguistics is not good, but I want to make progress, so I found a beep video on the Internet to learn C language
Leetcode123 timing of buying and selling stocks III
Disable scrolling in the iPhone web app- Disable scrolling in an iPhone web application?
Installing QT plug-in in Visual Studio
About%*s and%* s
Breakpad usage and DMP analysis
Judging the number of leap years from 1 to N years
Daily question, magic square simulation
Luogu p5707 [deep foundation 2. example 12] late for school
[paper notes] overview of case segmentation