当前位置:网站首页>Stress test modification solution
Stress test modification solution
2022-07-02 06:44:00 【Dairyzz】
primary :
Introduce
The project is xxl-job Next scheduled task Own an actuator Therefore, it can be enabled according to one node Exclusive port
The project java Package configuration :
jdk8
Memory size :2GB
Do not use third-party caching and message processing software Pure primary
Business content : Accept messages of Foreign Exchange , Analytic message , Determine the message type , Judge the primary key of the message to be processed , Update if in the database , If not in the database, insert ( The number of message primary keys is small , Mainly update , The operation of inserting is negligible )
Processing mode : Adopted LinkedBlockingQueue Put all the received messages into the queue
Then start another thread to process the queue information Then judge whether the message is processed before database operation
Under pressure test :
The pressure test time is one hour and the data volume is one million , The amount of data to be processed is 5w about
Pressure test 10 Minutes less than Queue memory exceeded 2G The direct stack is full
PLAN1
Processing mode : Judge and process the message before inserting it into the queue , Only the messages that need to be processed are added to the blocking queue
Under pressure test :
A little smoother than the original way , but 20 Minutes or so, the stack exploded , Check the log and find that the queue has been inserted within one second 100 Data to be processed , But one second only deals with 10 Data , The processing speed is far from keeping up .
PLAN2
Processing mode : Put the message into memory , Create a management class , The thread receiving the message calls this managed class to insert the message into the corresponding map in , The thread processing the message calls this managed class to take out the data that needs to be updated and update .
The reason for this treatment : The processing speed in memory is faster than that of querying the database to determine whether to process , Many messages correspond to the same primary key, and the operation of the database is more about updating , Will not squash the stack
Processing steps :
- Create a message class that is compatible with all message fields ( Take the union of all messages ) And whether to update the field
- Create a management class There is a private map key Primary key value It is a message class There is an add method in the management class , Set the received message update field to true, And then put in map in , There is also a method in the management class to get the message queue that needs to be updated , First new A blocking queue pair map Traversal will update the field to true The message class update field of is set to false Then put it into the blocking queue , Finally, return to the blocking queue
- The thread receiving the message calls the add method The thread processing the message calls the method of obtaining and updating the message queue , Process the data in the queue
Because these two methods are similar to write and read operations , So both methods should be locked
Writing of management class :
private HashMap<String, BankQuoteNode> quoteMap = new HashMap<>();//k It is your primary key
@Override
public synchronized void addQuote(BankQuoteNode node) {
node.setUpdateFlag(true);
StringBuilder key = new StringBuilder();
key.append(node.getMarketInicator()).append('-').append(node.getSecurityCode()).append('-').append(node
.getSecurityName());
String quoteMapKey=key.toString();
quoteMap.put(quoteMapKey,node);
}
@Override
public synchronized Queue<BankQuoteNode> getAllQuote() {
LinkedBlockingQueue<BankQuoteNode> quoteQueue =new LinkedBlockingQueue<>();
quoteMap.forEach((k,v)->{
quoteQueue.add(v);
});
return quoteQueue;// Back to all
}
@Override
public synchronized Queue<BankQuoteNode> getRefreshedQuote() {
LinkedBlockingQueue<BankQuoteNode> refreshedQuoteQueue = new LinkedBlockingQueue<>();
// Traverse quoteMap
// hold UpdateFlag=true Of node Insert the returned queue
quoteMap.forEach((k,v)->{
if(v.isUpdateFlag()){
quoteMap.get(k).setUpdateFlag(false);
refreshedQuoteQueue.add(v);
}
});
return refreshedQuoteQueue;
}
边栏推荐
猜你喜欢

js中map和forEach的用法

Code skills - Controller Parameter annotation @requestparam

How to try catch statements that return promise objects in JS

20201002 vs 2019 qt5.14 developed program packaging

Build learning tensorflow

Vscode installation, latex environment, parameter configuration, common problem solving

pytest(1) 用例收集规则

ctf-web之练习赛

The default Google browser cannot open the link (clicking the hyperlink does not respond)

Redis——大Key問題
随机推荐
Function execution space specifier in CUDA
js中对于返回Promise对象的语句如何try catch
Redis - grande question clé
Redis——热点key问题
js中map和forEach的用法
Thread hierarchy in CUDA
实现strStr() II
web自动化切换窗口时报错“list“ object is not callable
默认google浏览器打不开链接(点击超链接没有反应)
Detailed definition of tensorrt data format
JS modification element attribute flipping commonly used in selenium's Web Automation
qq邮箱接收不到jenkins构建后使用email extension 发送的邮件(timestamp 或 auth.......)
A preliminary study on ant group G6
如何调试微信内置浏览器应用(企业号、公众号、订阅号)
There is no way to drag the win10 desktop icon (you can select it, open it, delete it, create it, etc., but you can't drag it)
Eggjs -typeorm 之 TreeEntity 实战
virtualenv和pipenv安装
Apt command reports certificate error certificate verification failed: the certificate is not trusted
Redis——Cluster数据分布算法&哈希槽
Cglib agent - Code enhancement test