当前位置:网站首页>Concept and implementation of QPS
Concept and implementation of QPS
2022-06-26 03:45:00 【thoughtCodes】
QPS Concept and implementation of
Survive by day and develop by night.
talk is cheap, show me the code,make a better result.
Catalog
summary
QPS Is a very common requirement .
demand :
1.QPS The implementation of the
package qps.demo;
/** * @desc QPS Controller test * @author visy.wang * @date 2020/9/29 10:25 */
public class Main {
/** * In multithreaded environment , Please make sure you get it QPSCtrl Object is the same , * It is recommended to initialize here , Of course, it can also be created in other ways ( But it must be the same ) * Different QPSCtrl Objects are independent of each other */
private static QPSCtrl qpsCtrl1 = QPSCtrl.create(1);
// private static QPSCtrl qpsCtrl2 = QPSCtrl.create(3);
public void test1(int i){
// call ctrl() To achieve QPS The control of
// System.out.println(Thread.currentThread().getName()+"\t"+System.currentTimeMillis()+" Start visiting \n");
// System.out.println(Thread.currentThread().getName());
qpsCtrl1.ctrl();
System.out.println(Thread.currentThread().getName()+"\t"+i+"(I) ");
// System.out.println(System.currentTimeMillis()+"END");
}
// public void test2(int i){
// // beyond QPS Value will block here , Until the next cycle
// qpsCtrl2.ctrl();
// System.out.print(i+"(II) ");
// }
public static void main(String[] args) {
long startTime = System.currentTimeMillis();
// System.out.println(" Start and end "+startTime);
Main testQPS = new Main();
new Thread(()->{
for(int i=1; i<=3; i++){
testQPS.test1(i);
}
}).start();
new Thread(()->{
for(int i=4; i<=6; i++){
testQPS.test1(i);
}
}).start();
long endTime=0L;
new Thread(()->{
for(int i=7; i<=12; i++){
testQPS.test1(i);
}
}).start();
endTime = System.currentTimeMillis();
// System.out.println(" Start and end "+endTime);
// new Thread(()->{
// for(int i=13; i<=18; i++){
// testQPS.test2(i);
// }
// }).start();
System.out.println(" Time consuming "+Long.valueOf(endTime-startTime));
}
}
test log:
Time consuming 90
1656172702613=====================
Thread-2 7(I)
1656172703613=====================
Thread-2 8(I)
1656172704649=====================
Thread-0 1(I)
1656172705656=====================
Thread-0 2(I)
1656172706656=====================
Thread-1 4(I)
1656172707656=====================
Thread-1 5(I)
1656172708656=====================
Thread-1 6(I)
1656172709656=====================
Thread-0 3(I)
1656172710656=====================
Thread-2 9(I)
1656172711656=====================
Thread-2 10(I)
1656172712656=====================
Thread-2 11(I)
1656172713656=====================
Thread-2 12(I)
What I wonder is why the final output takes time ?
Design thinking
nothing
Analysis of implementation ideas
1.QPS Realization
Expand to achieve
Reference here :github: Simply implement the above process :
Entry level implementation :
: Partial source code implementation .
: The source code to achieve
Performance parameter test :
nothing
References and recommended readings
Welcome to , Dear brother , If it helps you , A little praise and a little attention !~
边栏推荐
- [hash table] improved, zipper hash structure - directly use two indexes to search, instead of hashing and% every time
- Is the waiting insurance record a waiting insurance evaluation? What is the relationship between the two?
- Uni app custom selection date 1 (September 16, 2021)
- Sqlitestudio download address
- Todolist incomplete, completed
- 2022.6.20-----leetcode.715
- Kotlin uses viewpager2+fragment+bottomnavigationview to implement the style of the switching module of the bottom menu bar.
- Redux thunk simple case, advantages, disadvantages and thinking
- Upload file / text / picture, box shadow
- EF core Basics
猜你喜欢

请求对象,发送请求

Tupu software is the digital twin of offshore wind power, striving to be the first

Comparison of static methods and variables with instance methods and variables

阿里云函数计算服务一键搭建Z-Blog个人博客

用eclipse连mysql数据库出错然后出现图中的话是咋回事呀

Drag and drop

Graphics card, GPU, CPU, CUDA, video memory, rtx/gtx and viewing mode

ASP. Net core introduction
HL7Exception: Can‘t XML-encode a GenericMessage. Message must have a recognized struct

云计算基础-0
随机推荐
MySQL advanced Chapter 1 (installing MySQL under Linux) [2]
虚拟化是什么意思?包含哪些技术?与私有云有什么区别?
进程之间的通信方式
[hash table] a very simple zipper hash structure, so that the effect is too poor, there are too many conflicts, and the linked list is too long
Solve the problem that the input box is blocked by the pop-up keyboard under the WebView transparent status bar
Kotlin learning apply plugin: 'kotlin Android extensions‘
169. 多数元素
View of MySQL
MySQL高級篇第一章(linux下安裝MySQL)【下】
Nebula Graph学习篇3_多线程完成6000w+关系数据迁移
Deletelater Usage Summary in QT
优化——多目标规划
TiFlash 函数下推必知必会丨十分钟成为 TiFlash Contributor
用eclipse连mysql数据库出错然后出现图中的话是咋回事呀
2022.6.23-----leetcode.30
Is it safe to open a fund account? How to apply
2022.6.20-----leetcode.715
智能制造学习记录片和书籍
Mysql database foundation
Digital twin intelligent water service, breaking through the development dilemma of sponge City