怎么用go配置mysql连接池
发表于:2024-10-17 作者:千家信息网编辑
千家信息网最后更新 2024年10月17日,这篇文章主要讲解了"怎么用go配置mysql连接池",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"怎么用go配置mysql连接池"吧!go配置mysql
千家信息网最后更新 2024年10月17日怎么用go配置mysql连接池
这篇文章主要讲解了"怎么用go配置mysql连接池",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"怎么用go配置mysql连接池"吧!
go配置mysql连接池
mysql配置文档
max-connections=10000
代码
orm
1.ab 发起并发请求测试
-c: 并发量100
-n: 总请求量300
➜ ~ ab -c 100 -n 300 "http://localhost:8080/pool"This is ApacheBench, Version 2.3 <$Revision: 1826891 $>Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/Licensed to The Apache Software Foundation, http://www.apache.org/Benchmarking localhost (be patient)Completed 100 requestsCompleted 200 requestsCompleted 300 requestsFinished 300 requestsServer Software:Server Hostname: localhostServer Port: 8080Document Path: /poolDocument Length: 304 bytesConcurrency Level: 100Time taken for tests: 4.073 secondsComplete requests: 300Failed requests: 0Total transferred: 128400 bytesHTML transferred: 91200 bytesRequests per second: 73.66 [#/sec] (mean)Time per request: 1357.601 [ms] (mean)Time per request: 13.576 [ms] (mean, across all concurrent requests)Transfer rate: 30.79 [Kbytes/sec] receivedConnection Times (ms) min mean[+/-sd] median maxConnect: 0 2 2.2 1 8Processing: 1001 1012 8.2 1010 1036Waiting: 1001 1012 8.1 1010 1036Total: 1002 1014 9.5 1012 1043Percentage of the requests served within a certain time (ms) 50% 1012 66% 1016 75% 1019 80% 1021 90% 1031 95% 1035 98% 1039 99% 1040 100% 1043 (longest request)➜ ~
2.PoolHandler 中触发sql查询
设置空闲连接为10个
最大可以打开的连接为10个 mysql.conf中可以修改最大连接数.
db/db.go
sqlDB.SetMaxIdleConns(10) // SetMaxOpenConns 设置打开数据库连接的最大数量。 sqlDB.SetMaxOpenConns(10) // SetConnMaxLifetime 设置了连接可复用的最大时间。 sqlDB.SetConnMaxLifetime(time.Hour)
controller/pool.go
func PoolHandler(c *gin.Context) { time.Sleep(time.Second) var user model.User tx := db.DB.Raw("SELECT id, name, age FROM users WHERE name = ? limit 1", "D42").Scan(&user) if tx.Error != nil { panic(tx.Error) } logger.Debugf("raw sql id:%v name:%v age:%v", user.ID, user.Name, user.Age) c.JSON(200, user)}
3.查看测试过程中请求mysql创建的请求
SHOW PROCESSLIST;
Id User Host db Command Time State Info8 root localhost:51148 demo_go Query 0 starting SHOW PROCESSLIST900 root localhost:64598 demo_go Sleep 0 901 root localhost:64754 demo_go Sleep 0 902 root localhost:64755 demo_go Sleep 0 903 root localhost:64756 demo_go Sleep 0 904 root localhost:64757 demo_go Sleep 0 905 root localhost:64758 demo_go Sleep 0 906 root localhost:64759 demo_go Sleep 0 907 root localhost:64760 demo_go Sleep 0 908 root localhost:64761 demo_go Sleep 0 909 root localhost:64762 demo_go Sleep 0
感谢各位的阅读,以上就是"怎么用go配置mysql连接池"的内容了,经过本文的学习后,相信大家对怎么用go配置mysql连接池这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是,小编将为大家推送更多相关知识点的文章,欢迎关注!
配置
最大
学习
内容
测试
代码
就是
思路
情况
数据
数据库
数量
文档
文章
时间
更多
知识
知识点
空闲
篇文章
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
海外元器件数据库
网络安全问题论文
行研数据库
西安游戏软件开发公司应贾晨
网络安全设备图片
软件开发工程师报考条件
网易游戏软件开发
crt连接海康服务器
铜仁app软件开发定制
你我身边的网络安全
久和网络技术工作室官方帐号
湖北东塔网络安全特训营实战教学
往数据库批量插入数据
下列行为符合网络安全法的是
北京软件开发平台公司
蚂蚁机器人软件开发
麒麟系统安装perl连接数据库
商城类项目数据库
lol水晶之痕的服务器在哪儿
网络安全培训会背景
网络安全主题班会效果及反思
七日杀20服务器修改器
腾讯云服务器138 年
苏州网络安全基地
国开网络技术基础模拟测试3
计算机三级网络技术网课资源
社会力量参与救灾数据库
新冠病毒网络安全
数据库技术与应用试题库
益阳计算机软件开发