当前位置:网站首页>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

边栏推荐
- Struggle, programmer -- Chapter 47 the so-called Iraqis are on the water side
- [Software Engineering] planning and project management
- Unity's rich text color sets the color to be fully transparent
- Mysql学习笔记2022
- 扩散模型又杀疯了!这一次被攻占的领域是...
- Phpstudy 2016 build Pikachu range
- Mobile learning notes of u++ programming
- [Software Engineering] design module
- 接了个私活项目,一下赚了15250,还有必要做主业吗?
- 一文彻底弄懂建造者模式(Builder)
猜你喜欢
![Front and back management system of dessert beverage store based on SSM framework dessert mall cake store [source code + database]](/img/1b/9060d58d4dbb7f6f3c3a58959b7f14.png)
Front and back management system of dessert beverage store based on SSM framework dessert mall cake store [source code + database]

Driving the efficient growth of the manufacturing industry, UFIDA u9 cloud is constantly improving the password behind it

FreeRtos 任务优先级和中断优先级

那些没考上大学的人,后来过的怎样

Software architecture

keil MDK 中使用虚拟串口调试串口

难怪考研热度这么高,这些是研究生才有的“隐藏福利”!
![[graduation project] Research on emotion analysis based on semi supervised learning and integrated learning](/img/02/33d7b6a5bc01737c5dbeb944202a66.jpg)
[graduation project] Research on emotion analysis based on semi supervised learning and integrated learning

Deadlock found when trying to get lock; Try restarting transaction

Reading of double pointer instrument panel (II) - Identification of dial position
随机推荐
U++ 运营商 学习笔记
Mysql学习笔记2022
Sikulix select the picture of relative position (advanced version)
Network address translation nat
Using pictures to locate app elements sikulix
同花顺开户难么?网上开户安全么?
Le modèle de diffusion est encore fou! Cette fois - ci, la zone occupée était...
数据采集之:巧用布隆过滤器提取数据摘要
[Software Engineering] design module
Thoroughly understand the builder mode (builder)
U++ programming array learning notes
11 method reference and constructor application
基于SSH框架甜品商城管理系统【源码+数据库】
Can Google bidding account detect the global market?
Redistemplate serialization
C # WinForm photo album function, picture zooming, dragging, preview Pagination
Fluentd is easy to get started. Combined with the rainbow plug-in market, log collection is faster
扩散模型又杀疯了!这一次被攻占的领域是...
网络地址转换NAT
【浙江大学】考研初试复试资料分享