当前位置:网站首页>压力测试修改解决方案
压力测试修改解决方案
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;
}
边栏推荐
- Flutter hybrid development: develop a simple quick start framework | developers say · dtalk
- 浅谈三点建议为所有已经毕业和终将毕业的同学
- ROS create workspace
- 日志(常用的日志框架)
- IDEA公布全新默认UI,太清爽了(内含申请链接)
- Data playback partner rviz+plotjuggler
- Support new and old imperial CMS collection and warehousing tutorials
- Bgp Routing preference Rules and notice Principles
- CUDA中的函数执行空间说明符
- 锐捷EBGP 配置案例
猜你喜欢
Linear DP (split)
Learn about various joins in SQL and their differences
Contest3147 - game 38 of 2021 Freshmen's personal training match_ G: Flower bed
Community theory | kotlin flow's principle and design philosophy
队列(线性结构)
注解和反射详解以及运用
WLAN相关知识点总结
Data playback partner rviz+plotjuggler
CNN visualization technology -- detailed explanation of cam & grad cam and concise implementation of pytorch
Common means of modeling: combination
随机推荐
CUDA中的存储空间修饰符
In depth understanding of JUC concurrency (II) concurrency theory
Redis---1. Data structure characteristics and operation
Current situation analysis of Devops and noops
LeetCode 83. Delete duplicate elements in the sorting linked list
加密压缩文件解密技巧
Database learning summary 5
LeetCode 83. 删除排序链表中的重复元素
Find the highest value of the current element Z-index of the page
Common means of modeling: combination
数据科学【九】:SVD(二)
Classic literature reading -- deformable Detr
It is said that Kwai will pay for the Tiktok super fast version of the video? How can you miss this opportunity to collect wool?
Eco express micro engine system has supported one click deployment to cloud hosting
Contest3147 - game 38 of 2021 Freshmen's personal training match_ G: Flower bed
网络相关知识(硬件工程师)
From design delivery to development, easy and efficient!
LeetCode 283. Move zero
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.)
标签属性disabled selected checked等布尔类型赋值不生效?