当前位置:网站首页>Database connection pool: stress testing
Database connection pool: stress testing
2022-06-22 15:05:00 【_ Soren】
Preface
The time taken to verify the insertion of data , The first test uses ordinary database access operations , The second test uses the database access operation with connection pool , Compare the time spent in two operations with the same amount of data .
List of articles
Single thread test
One 、 Without connection pool
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include "Connection.h"
#include "CommonConnectionPool.h"
using namespace std;
int main(void) {
clock_t begin = clock();
for (int i = 1; i <= 1000; ++i)
{
Connection conn;
char sql[1024] = {
0 };
sprintf(sql, "insert into user(id, name, age, sex) values(%d, '%s', %d, '%s')",
i, "zhangsan", 20, "male");
conn.connect("127.0.0.1", 3306, "root", "123456", "chat");
conn.update(sql);
}
clock_t end = clock();
cout << (end - begin) << "ms" << endl;
return 0;
}
for Cyclic sequential measurement 1000 Data 、5000 Data 、10000 Data
1. Insert 1000 Data tests



Average :11866ms
2. Insert 5000 Data



Average :59581ms
3. Insert 10000 Data



Average :120634ms
Two 、 With connection pool
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include "Connection.h"
#include "CommonConnectionPool.h"
using namespace std;
int main(void) {
clock_t begin = clock();
ConnectionPool* cp = ConnectionPool::getConnectionPool();
for (int i = 1; i <= 1000; ++i)
{
shared_ptr<Connection> sp = cp->getConnection();
char sql[1024] = {
0 };
sprintf(sql, "insert into user(id, name, age, sex) values(%d, '%s', %d, '%s')",
i, "zhangsan", 20, "male");
sp->update(sql);
}
clock_t end = clock();
cout << (end - begin) << "ms" << endl;
return 0;
}
1. Insert 1000 Data



Average. :3226ms
2. Insert 5000 Data



Average :17498ms
3. Insert 10000 Data



Average :34179ms
contrast

Four thread test
One 、 Without connection pool
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include "Connection.h"
#include "CommonConnectionPool.h"
using namespace std;
int main(void) {
Connection conn;
conn.connect("127.0.0.1", 3306, "root", "123456", "chat");
clock_t begin = clock();
thread t1([]() {
ConnectionPool* cp = ConnectionPool::getConnectionPool();
for (int i = 1; i <= 250; ++i)
{
Connection conn;
char sql[1024] = {
0 };
sprintf(sql, "insert into user(id, name, age, sex) values(%d, '%s', %d, '%s')",
i, "zhangsan", 20, "male");
conn.connect("127.0.0.1", 3306, "root", "123456", "chat");
conn.update(sql);
}
});
thread t2([]() {
ConnectionPool* cp = ConnectionPool::getConnectionPool();
for (int i = 1; i <= 250; ++i)
{
Connection conn;
char sql[1024] = {
0 };
sprintf(sql, "insert into user(id, name, age, sex) values(%d, '%s', %d, '%s')",
i, "zhangsan", 20, "male");
conn.connect("127.0.0.1", 3306, "root", "123456", "chat");
conn.update(sql);
}
});
thread t3([]() {
ConnectionPool* cp = ConnectionPool::getConnectionPool();
for (int i = 1; i <= 250; ++i)
{
Connection conn;
char sql[1024] = {
0 };
sprintf(sql, "insert into user(id, name, age, sex) values(%d, '%s', %d, '%s')",
i, "zhangsan", 20, "male");
conn.connect("127.0.0.1", 3306, "root", "123456", "chat");
conn.update(sql);
}
});
thread t4([]() {
ConnectionPool* cp = ConnectionPool::getConnectionPool();
for (int i = 1; i <= 250; ++i)
{
Connection conn;
char sql[1024] = {
0 };
sprintf(sql, "insert into user(id, name, age, sex) values(%d, '%s', %d, '%s')",
i, "zhangsan", 20, "male");
conn.connect("127.0.0.1", 3306, "root", "123456", "chat");
conn.update(sql);
}
});
t1.join();
t2.join();
t3.join();
t4.join();
clock_t end = clock();
cout << (end - begin) << "ms" << endl;
return 0;
}
1. Insert 1000 data



Average :2882ms
2. Insert 5000 data



Average :13465ms
3. Insert 10000 data


Average :26191ms
Two 、 With connection pool
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include "Connection.h"
#include "CommonConnectionPool.h"
using namespace std;
int main(void) {
clock_t begin = clock();
thread t1([]() {
ConnectionPool* cp = ConnectionPool::getConnectionPool();
for (int i = 1; i <= 250; ++i)
{
char sql[1024] = {
0 };
sprintf(sql, "insert into user(id, name, age, sex) values(%d, '%s', %d, '%s')",
i, "zhangsan", 20, "male");
shared_ptr<Connection> sp = cp->getConnection();
sp->update(sql);
}
});
thread t2([]() {
ConnectionPool* cp = ConnectionPool::getConnectionPool();
for (int i = 251; i <= 500; ++i)
{
char sql[1024] = {
0 };
sprintf(sql, "insert into user(id, name, age, sex) values(%d, '%s', %d, '%s')",
i, "zhangsan", 20, "male");
shared_ptr<Connection> sp = cp->getConnection();
sp->update(sql);
}
});
thread t3([]() {
ConnectionPool* cp = ConnectionPool::getConnectionPool();
for (int i = 501; i <= 750; ++i)
{
char sql[1024] = {
0 };
sprintf(sql, "insert into user(id, name, age, sex) values(%d, '%s', %d, '%s')",
i, "zhangsan", 20, "male");
shared_ptr<Connection> sp = cp->getConnection();
sp->update(sql);
}
});
thread t4([]() {
ConnectionPool* cp = ConnectionPool::getConnectionPool();
for (int i = 751; i <= 1000; ++i)
{
char sql[1024] = {
0 };
sprintf(sql, "insert into user(id, name, age, sex) values(%d, '%s', %d, '%s')",
i, "zhangsan", 20, "male");
shared_ptr<Connection> sp = cp->getConnection();
sp->update(sql);
}
});
t1.join();
t2.join();
t3.join();
t4.join();
clock_t end = clock();
cout << (end - begin) << "ms" << endl;
return 0;
}
1. Insert 1000 data



Average :1269ms
2. Insert 5000 data



Average :6185ms
3. Insert 10000 data



Average :11717ms
contrast

边栏推荐
- 拜登签署两项旨在加强政府网络安全的新法案
- Specific methods and steps of PROFINET communication between s7-200smart and Fanuc robot
- Phpstudy 2016 build Pikachu range
- 【直播回顾】战码先锋第六期:共建测试子系统,赋能开发者提
- 直播出海 | 国内直播间再出爆品,「外卷」全球如何致胜
- As a passer-by, some advice for programmers who are new to the workplace
- 同花顺开户难么?网上开户安全么?
- [Software Engineering] planning and project management
- Error: Unable to find a match: lrzsz的解决方法
- 那些没考上大学的人,后来过的怎样
猜你喜欢

接了个私活项目,一下赚了15250,还有必要做主业吗?

利用图片实现APP元素定位sikulix

Simulation Keil et vspd

直播出海 | 国内直播间再出爆品,「外卷」全球如何致胜

封装api时候token的处理
![[PR] basic process](/img/e6/13a5703cfb8e5c51ed06fe9b0d9485.png)
[PR] basic process

Countdown to the conference - Amazon cloud technology innovation conference invites you to build a new AI engine!

Specific methods and steps of PROFINET communication between s7-200smart and Fanuc robot
![[Software Engineering] planning and project management](/img/93/4b5b5034fbfb76adef1b4fe93a85cb.png)
[Software Engineering] planning and project management

拜登签署两项旨在加强政府网络安全的新法案
随机推荐
Biden signe deux nouvelles lois visant à renforcer la cybersécurité du Gouvernement
Fight, programmer chapter 43 kill one man in ten steps
Common real machine debugging plug-ins for unity commercial games
网络地址转换NAT
Can Google bidding account detect the global market?
Fluentd is easy to get started. Combined with the rainbow plug-in market, log collection is faster
Unity sub thread calls UI of main thread
网站存在的价值是什么?为什么要搭建独立站
Sword finger offer46 -- translate numbers into strings
那些令人懵逼的用户态&内核态
New hybrid architecture iformer! Flexible migration of convolution and maximum pooling to transformer
一文彻底弄懂单例模式(Singleton)
Reading of double pointer instrument panel (II) - Identification of dial position
拜登签署两项旨在加强政府网络安全的新法案
bochs 软件使用记录
数据采集之:巧用布隆过滤器提取数据摘要
Thoroughly understand the factory mode
How to use SQL to modify in the database & delete
Thoroughly understand the builder mode (builder)
C # WinForm photo album function, picture zooming, dragging, preview Pagination