当前位置:网站首页>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 .
边栏推荐
- iconv_ Open returns error code 22
- QT file reading -qfile
- Brain tree (I)
- System Verilog — interface
- Is it safe to open a stock account online?
- 5 connection modes of QT signal slot
- Leetcode123 timing of buying and selling stocks III
- 在打新债开户证券安全吗,需要什么准备
- AB string interchange
- Core mode and immediate rendering mode of OpenGL
猜你喜欢
Build a minimalist gb28181 gatekeeper and gateway server, establish AI reasoning and 3D service scenarios, and then open source code (I)
Dynamic memory allocation
Solution of push code failure in idea
Learning notes on February 8, 2022 (C language)
Mining procedure processing
Esp8266 building smart home system
Arithmetic operations and expressions
Review of arrays and pointers triggered by a topic
Std:: vector minutes
Data preprocessing - normalization and standardization
随机推荐
Work of the first week
From 408 to independent proposition, 211 to postgraduate entrance examination of Guizhou University
Is it safe to open a stock account through the account opening link of the account manager?
High precision addition
JSON module dictionary and string conversion
Learning to Measure Changes: Fully Convolutional Siamese Metric Networks for Scene Change Detection
Source code analysis of synergetics and ntyco
Custom structure type
Esp8266 building smart home system
(1) Introduction
Is it safe to open an online stock account? Who knows
Pytorch distributed test pit summary
QT animation loading and closing window
Usage of pure virtual functions
Qt: Pro project file
GDB debugging
Learning notes on February 5, 2022 (C language)
Usage of qlist
How to deal with mining process
Advertising effect cluster analysis (kmeans)