当前位置:网站首页>压力测试修改解决方案
压力测试修改解决方案
2022-07-02 06:17:00 【Dairyzz】
原:
介绍
该项目是xxl-job下的一个定时任务 自己独占一个执行器 所以可以按照一个节点进行启用 独占一个端口
该项目的java包配置:
jdk8
内存大小:2GB
不采用第三方缓存和消息处理软件 纯原生
业务内容:接受外汇的报文,解析报文,判断报文类型,对需要处理的报文的主键进行判断,如果数据库中由则更新,如果数据库中没有则插入 (报文主键的数量少,以更新为主,插入的操作可以忽略不计)
处理方式:采用的LinkedBlockingQueue 将接受到的报文全部塞到队列里
然后另起一个线程处理队列信息 然后判断报文是否处理再进行数据库操作
压力测试下情况:
压力测试时间为一小时数据量为百万,需要处理的数据量在5w左右
压力测试10分钟不到 队列内存超过2G 直接堆栈爆满
PLAN1
处理方式:在塞入队列前进行报文的判断处理,是需要处理的报文才加入阻塞队列中
压力测试下情况:
比原来的方式平缓一点,但20分钟左右堆栈爆掉了了,查看日志发现队列一秒内插入了 100条需处理的数据,但一秒钟只处理10条数据,处理速度远远跟不上。
PLAN2
处理方式:将报文放入内存中,创建一个管理的类,接受报文的线程线程调用这个管理的类将报文塞入对应的map中,处理报文的线程调用这个管理的类将需要更新的数据取出进行更新。
这样处理的原因:内存中的处理速度比查询数据库判断是否要处理的速度快,很多报文对应的主键是同一个对于数据库的操作更多的是更新,不会挤压堆栈
处理步骤:
- 创建一个报文类兼容所有报文的字段(取所有报文的并集)和一个是否更新字段
- 创建一个管理类 管理类中有一个私有的map key为主键 value为报文类 管理类中有一个添加方法,将接受到的报文更新字段设为true,然后放入map中, 管理类中还有一个获取需要更新报文队列的方法,先new一个阻塞队列对map进行遍历将更新字段为true的报文类更新字段设为false然后放入阻塞队列中,最后返回阻塞队列
- 接收报文的线程调用添加方法 处理报文的线程调用获取更新报文队列的方法,处理队列中的数据
因为这两个方法类似写和读的操作,所以两个方法上都要加上锁
管理类的写法:
private HashMap<String, BankQuoteNode> quoteMap = new HashMap<>();//k是自己的主键
@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;//返回所有
}
@Override
public synchronized Queue<BankQuoteNode> getRefreshedQuote() {
LinkedBlockingQueue<BankQuoteNode> refreshedQuoteQueue = new LinkedBlockingQueue<>();
//遍历quoteMap
//把UpdateFlag=true的node插入返回的队列
quoteMap.forEach((k,v)->{
if(v.isUpdateFlag()){
quoteMap.get(k).setUpdateFlag(false);
refreshedQuoteQueue.add(v);
}
});
return refreshedQuoteQueue;
}
边栏推荐
- Amazon AWS data Lake Work Pit 1
- ShardingSphere-JDBC篇
- BGP中的状态机
- Generic classes and parameterized classes of SystemVerilog
- Zhuanzhuanben - LAN construction - Notes
- The difference between session and cookies
- Database learning summary 5
- AttributeError: ‘str‘ object has no attribute ‘decode‘
- Linear DP (split)
- No subject alternative DNS name matching updates. jenkins. IO found, the reason for the error and how to solve it
猜你喜欢
一口气说出 6 种实现延时消息的方案
来自读者们的 I/O 观后感|有奖征集获奖名单
日期时间API详解
CUDA中的Warp Shuffle
【张三学C语言之】—深入理解数据存储
Little bear sect manual query and ADC in-depth study
深入了解JUC并发(二)并发理论
Contest3147 - game 38 of 2021 Freshmen's personal training match_ 1: Maximum palindromes
Contest3147 - game 38 of 2021 Freshmen's personal training match_ G: Flower bed
数据科学【八】:SVD(一)
随机推荐
WLAN相关知识点总结
Find the highest value of the current element Z-index of the page
Ruijie ebgp configuration case
加密压缩文件解密技巧
CUDA中的Warp Shuffle
Data science [9]: SVD (2)
网络相关知识(硬件工程师)
Summary of WLAN related knowledge points
LeetCode 39. Combined sum
Reading classic literature -- Suma++
Sentinel规则持久化到Nacos
深入学习JVM底层(四):类文件结构
BGP routing optimization rules and notification principles
The Chinese word segmentation task is realized by using traditional methods (n-gram, HMM, etc.), neural network methods (CNN, LSTM, etc.) and pre training methods (Bert, etc.)
LeetCode 83. Delete duplicate elements in the sorting linked list
Zhuanzhuanben - LAN construction - Notes
LeetCode 39. 组合总和
Sentinel 阿里开源流量防护组件
Is there a really free applet?
CNN visualization technology -- detailed explanation of cam & grad cam and concise implementation of pytorch