日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql每秒最多能插入多少条数据 ? 死磕性能压测

發布時間:2025/3/20 数据库 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql每秒最多能插入多少条数据 ? 死磕性能压测 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

2019獨角獸企業重金招聘Python工程師標準>>>

前段時間搞優化,最后瓶頸發現都在數據庫單點上。 問DBA,給我的寫入答案是在1W(機械硬盤)左右。

聯想起前幾天infoQ上一篇文章說他們最好的硬件寫入速度在2W后也無法提高(SSD硬盤)

但這東西感覺從來沒證實過,故一時興起,弄臺虛擬機壓測起來。

?

想搞清下面的問題:

?

1,mysql支撐多少連接數?

2,寫入瓶頸到底是多少?

3,求QPS

?

暢想:?

足夠的CPU, load>遠小于核數*2

足夠的內存, 基本只用到物理內存

瓶頸在硬盤,寫入速度應該能到90-100M/S(機械硬盤,7200轉)。 故:預計kB_wrtn/s在90M左右

?

?

準備階段:

?

硬件:

壓測機I5雙核,8G內存, 開一個虛擬機+mysql,一個eclipse,一個jmeter

?

?

MYSQL準備

?

mysql基本命令

停止:

root@ubuntu:/home/hejinbin# /etc/init.d/mysql stop?
Stopping mysql (via systemctl): mysql.service.?

?

啟動:
root@ubuntu:/home/hejinbin# /etc/init.d/mysql start?
Starting mysql (via systemctl): mysql.service.

?

重啟:

/etc/init.d/mysql restart ?重啟mysql

?

查看當前mysq端口的連接數

netstat -apn|grep "3306"

?

?

查看mysql基本狀態?

show processlist; ?查看當前連接

show status; ? 查看當前數據庫狀態

show variables like 'max_connections' ?mysql當前最大連接數

?

set global max_connections=1000; ?設置當前最大連接數為1000

這個設置會馬上生效,但是當mysql重啟時這個設置會失效,需要長期生效在my.ini 添加 max_connections=1000

?

?

?

?

jmeter準備:

?

?

1,測試空壓測, 測試壓測客戶端能承受的線程數,?

?

只開聚合報告,其它圖形和結果樹輸出關閉。

?

?

?

經過測試,打開監視器圖形結果和結果樹輸出,本機空壓測也只能到1500附近,所以特別注意關閉這兩個,只開聚合報告,我的機器100個線程空壓測可以到壓測到6W吞吐量(throughput/sec)

?

后面也用100個線程進行mysql的插入壓測

?

?

JAVA測試類準備

?

用C3P0進行壓測:

?

C3P0:

?

1, 在classpath下放入?c3p0-config.xml 配置如下:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

<c3p0-config>

<default-config>

<property name="user">root</property>

<property name="password">hejinbin</property>

<property name="driverClass">com.mysql.jdbc.Driver</property>

<property name="jdbcUrl">jdbc:mysql://172.25.20.14:3306/Test?useUnicode=true

</property>

?

<property name="initialPoolSize">5</property>

<property name="maxIdleTime">5</property>

<property name="maxPoolSize">150</property>

<property name="minPoolSize">5</property>

</default-config>

?

</c3p0-config>

?

2,JAVA測試代碼

1 package org.test;2 3 import java.sql.Connection;4 import java.sql.ResultSet;5 import java.util.concurrent.atomic.AtomicLong;6 7 import com.mchange.v2.c3p0.ComboPooledDataSource;8 import com.mchange.v2.c3p0.impl.NewProxyPreparedStatement;9 10 /** 11 * hejinbin , QQ 107966750, C3P0的測試用例 2016-10-13 12 */ 13 public class C3P0Test { 14 public static AtomicLong id = new AtomicLong(1000000); 15 private static ComboPooledDataSource cpds = new ComboPooledDataSource(); 16 17 public static Long queryTest() throws Exception { 18 Long aid = null; 19 Connection con = null; 20 try { 21 // 從C3P0獲取連接 22 con = cpds.getConnection(); 23 NewProxyPreparedStatement prepare = (NewProxyPreparedStatement) con 24 .prepareStatement("select * from tbl_account_info where account_id = ?"); 25 prepare.setLong(1, 1001203); 26 ResultSet result = prepare.executeQuery(); 27 if (result.next()) { 28 aid = (result.getLong("aid")); 29 } 30 } catch (Exception e) { 31 throw e; 32 } finally { 33 // 此處關閉已經被C3P0重寫, 只是返還連接池 34 con.close(); 35 } 36 37 return aid; 38 } 39 40 public static void insertTest() throws Exception { 41 42 Connection con = null; 43 try { 44 // 從C3P0獲取連接 45 con = cpds.getConnection(); 46 NewProxyPreparedStatement prepare = (NewProxyPreparedStatement) con.prepareStatement( 47 "INSERT INTO `tbl_account_info` VALUES (?, '1231232132', '何錦彬測試', '12312312', '15018711111', 'hejinbin@qq.com', '1', 'hjb_recharge', 'yyUid:12312312', '1', '', '', '', '1399882974', '1429785062', '183.60.177.229', '1464658277', '14.29.83.74', '0', '0', '1', '0', '2', '1', '0', '1', '1', '1', '1', '1', '1', '1', '', '', '2000', '0', '0', '0', '2000', '6', '0', '0', '1', '0', '1456308697', '658', null, '廣東廣州', '0', '0', '0', '0', '20', null, null, '1', null, '');"); 48 prepare.setLong(1, id.incrementAndGet()); 49 prepare.execute(); 50 } catch (Exception e) { 51 throw e; 52 } finally { 53 // 此處關閉已經被C3P0重寫, 只是返還連接池 54 55 con.close(); 56 } 57 58 } 59 60 public static void main(String[] args) throws Exception { 61 for (int i = 0; i < 100000; i++) 62 insertTest(); 63 } 64 }

?

3,jmeter壓測相關代碼

package org.test.bin;import org.apache.jmeter.config.Arguments; import org.apache.jmeter.protocol.java.sampler.AbstractJavaSamplerClient; import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext; import org.apache.jmeter.samplers.SampleResult; import org.test.C3P0Test; import org.test.JDBCWthoutDBPoolTest;/*** hejinbin , QQ 107966750, C3P0的測試用例,放入jmeter中 2016-10-13*/ public class JDBWithC3P0JmertRuning extends AbstractJavaSamplerClient {// 填參數public Arguments getDefaultParameters() {Arguments params = new Arguments();return params;}// 測試查詢 // public SampleResult runTest(JavaSamplerContext arg0) { // SampleResult sr = new SampleResult(); // try { // sr.sampleStart(); // Long aid = C3P0Test.queryTest(); // // Long aid = 741l; // // 逾期值 // if (aid == 741) { // // 只有是預期值才判斷查詢成功 // sr.setSuccessful(true); // } else { // sr.setSuccessful(false); // } // } catch (Exception e) { // sr.setSuccessful(false); // e.printStackTrace(); // } finally { // sr.sampleEnd(); // } // return sr; // }public SampleResult runTest(JavaSamplerContext arg0) {SampleResult sr = new SampleResult();try {sr.sampleStart();C3P0Test.insertTest();// 只有是預期值才判斷查詢成功sr.setSuccessful(true);} catch (Exception e) {sr.setSuccessful(false);e.printStackTrace();} finally {sr.sampleEnd();}return sr;}}

整個工程地址 ?https://github.com/bensonHe/Test4DBInsert?

?

一切就緒, 開始死磕

?

第一次壓測配置(虛擬機):

?

數據庫服務器:1G內存+20G硬盤+1個CPU,單核

jmeter本地?

?

壓測結果

3100 左右

負載在6.77附近,判斷是CPU問題,加4核

?

?

第二次壓測配置(虛擬機):

?

1G內存+20G硬盤+1個CPU,4核

?直接到了5700附近,

?

?

total used free shared buffers cached?
Mem: 984 ?974 ? ? ? ? ? 9 1 132 455?
-/+ buffers/cache: 386 597?
Swap: 2044 31 ? ? ?2013?

只有9M剩余,預測增加物理內存可以繼續提高

?

?

?

?

第三次發現物理內存使用

4G內存+20G硬盤+1個CPU,4核

直接壓測到了 7500附近,IOWA% 在10附近,使用CPU 30%

?

?

?

?

此時服務器狀態, 9的WA

?

top - 00:55:47 up 15 min, 1 user, load average: 7.63, 2.61, 1.09?
Tasks: 175 total, 1 running, 174 sleeping, 0 stopped, 0 zombie?
%Cpu(s): 15.1 us, 40.6 sy, 0.0 ni, 28.3 id, 9.0 wa, 0.0 hi, 7.0 si, 0.0 st?
KiB Mem: 4038340 total, 1837716 used, 2200624 free, 151648 buffers?
KiB Swap: 2094076 total, 0 used, 2094076 free. 1224640 cached Mem?

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND?
2345 mysql 20 0 2539240 274992 13540 S 279.5 6.8 4:48.13 mysqld?

?

?

?

?

機器信息:

?

top - 01:02:07 up 21 min, 1 user, load average: 6.48, 6.91, 3.77?
Tasks: 175 total, 1 running, 174 sleeping, 0 stopped, 0 zombie?
%Cpu(s): 14.2 us, 33.2 sy, 0.0 ni, 35.0 id, 11.3 wa, 0.0 hi, 6.3 si, 0.0 st?
KiB Mem: 4038340 total, 2605868 used, 1432472 free, 152740 buffers?
KiB Swap: 2094076 total, 0 used, 2094076 free. 1965808 cached Mem?

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND?
2345 mysql 20 0 2540260 278508 13540 S 247.7 6.9 21:44.32 mysqld ? ? ? ?

?

CPU 4核, ?負載 6.48, ? 沒到瓶頸

內存, ?swap使用率是0, 也沒壓力

硬盤,

通過監控發現

Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn?
sda 688.00 0.00 17356.00 0 17356

?

硬盤寫入速度在 17M/s, 感覺還沒到瓶頸, 7200轉機械硬盤的是 90M

?

如何進一步優化,讓寫入速度達到瓶頸。 想到是配置mysql的參數了,下次繼續嘗試,有活要做了.

?

`不知道咋轉圖,?

  

轉載于:https://my.oschina.net/u/867417/blog/758690

總結

以上是生活随笔為你收集整理的mysql每秒最多能插入多少条数据 ? 死磕性能压测的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。