Mysql (Table: InnoDB, no index), after 0.5 million records are inserted in batches, it is getting slower and slower.

Source: Internet
Author: User
Insert 10000 records, insert 20000 records in 0 seconds, insert 30000 records in 2 seconds, insert 40000 records in 3 seconds, and insert 50000 records in 3 seconds, 60000 messages are inserted in 4 seconds, 70000 messages are inserted in 5 seconds, 80000 messages are inserted in 6 seconds, 90000 messages are inserted in 7 seconds, and 100000 messages are inserted in 8 seconds, 110000 messages are inserted in 9 seconds, 120000 messages are inserted in 11 seconds, 130000 messages are inserted in 12 seconds, 140000 messages are inserted in 13 seconds, and 150000 messages are inserted in 14 seconds, it takes 15 seconds to insert 160000 records... mysql

Insert 10000 records. it takes 0 seconds.
Insert 20000 records, in 2 seconds
Insert 30000 records, which takes 3 seconds
Insert 40000 records, which takes 3 seconds
Insert 50000 records, which takes 4 seconds
Insert 60000 records, in 5 seconds
Insert 70000 records, in 6 seconds
Insert 80000 records, in 7 seconds
Insert 90000 records, which takes 8 seconds
Insert 100000 records, in 9 seconds
Insert 110000 records, in 11 seconds
Insert 120000 records, in 12 seconds
Insert 130000 records, which takes 13 seconds
Insert 140000 records, in 14 seconds
Insert 150000 records, in 15 seconds
Insert 160000 records, in 16 seconds
Insert 170000 records. it takes 17 seconds.
Insert 180000 records, in 18 seconds
Insert 190000 Records, 19 seconds in use
Insert 200000 records, in 21 seconds
Insert 210000 records, in 22 seconds
Insert 220000 records, in 23 seconds
Insert 230000 records, which takes 25 seconds
Insert 240000 records, 26 seconds in use
Insert 250000 records, which takes 27 seconds
Insert 260000 records, which takes 28 seconds
Insert 270000 records, which takes 30 seconds
Insert 280000 records, 31 seconds in use
Insert 290000 records, in 32 seconds
Insert 300000 records, which takes 33 seconds
Insert 310000 records, which takes 34 seconds
Insert 320000 records, in 36 seconds
Insert 330000 records, in 37 seconds
Insert 340000 records, which takes 38 seconds
Insert 350000 records, in 39 seconds
Insert 360000 records, in 41 seconds
Insert 370000 records, in 42 seconds
Insert 380000 records, in 43 seconds
Insert 390000 records, in 44 seconds
Insert 400000 records, in 45 seconds
Insert 410000 records, 46 seconds in use
Insert 420000 records, in 48 seconds
Insert 430000 records, in 49 seconds
Insert 440000 records in 50 seconds
Insert 450000 records, in 52 seconds
Insert 460000 records, in 57 seconds
Insert 470000 records, in 66 seconds
Insert 480000 records, in 76 seconds
Insert 490000 records, 90 seconds in use
Insert 500000 records, in 105 seconds
Insert 510000 records, in 123 seconds
Insert 520000 records, in 142 seconds
Insert 530000 records, in 164 seconds
Insert 540000 records, in 187 seconds
Insert 550000 records, in 212 seconds
Insert 560000 records, in 239 seconds
Insert 570000 records, in 266 seconds
Insert 580000 records, in 294 seconds
Insert 590000 records, in 323 seconds
Insert 600000 records, in 358 seconds
Insert 610000 records, in 389 seconds
Insert 620000 records, in 421 seconds
Insert 630000 records, in 458 seconds
Insert 640000 records, in 496 seconds

Stop the program and run it again. it takes dozens of seconds for the first 10 thousand entries.
Clear the table and run it again. It takes tens of seconds to insert nearly 0.5 million records.

Public static void main (String [] args) {PreparedStatement pstmt = null; Connection conn = null; try {Class. forName ("com. mysql. jdbc. driver "); String url =" jdbc: mysql: // localhost: 3306/pis "; String username =" root "; String password =" root "; conn = DriverManager. getConnection (url, username, password); conn. setAutoCommit (false); String SQL = "SELECT T. id from PIS_PERSON_EX t where t. name like 'test % '"; PreparedStatement statement = conn. prepareStatement (SQL); ResultSet result = statement.exe cuteQuery (); String sql2 = "INSERT INTO PIS_RECORD (ID, RCTIMES, RCTIMEP, YEARS, MONTHS, DAYS, YMD, PERSONID, DEVICEID, NOTESTR) "+" VALUES (?,?,?,?,?,?,?,?,?,?) "; Pstmt = conn. prepareStatement (sql2); SimpleDateFormat sdf = new SimpleDateFormat ("yyyyMMddHHmmss"); Random random = new Random (); int pos = 0; Date t1 = new Date (); while (result. next () {for (int I = 1; I <= 31; I ++) {String day = I + ""; if (I <10) {day = "0" + I ;}for (int j = 0; j <5; j ++) {Date checkStartTime = new Date (sdf. parse ("201601" + day + "090000 "). getTime ()-(random. nextInt (21600000)-10800000); Date checkEndTime = new Date (sdf. parse ("201601" + day + "180000 "). getTime ()-(random. nextInt (21600000)-10800000); String checkStartTimeStr = sdf. format (checkStartTime); String checkEndTimeStr = sdf. format (checkEndTime); pstmt. setString (1, UUID. randomUUID (). toString (). replaceAll ("-", ""); pstmt. setString (2, checkStartTimeStr); pstmt. setTimestamp (3, new Timestamp (checkS TartTime. getTime (); pstmt. setString (4, checkStartTimeStr. substring (0, 4); pstmt. setString (5, checkStartTimeStr. substring (4, 6); pstmt. setString (6, checkStartTimeStr. substring (6, 8); pstmt. setString (7, checkStartTimeStr. substring (0, 8); pstmt. setString (8, result. getString (1); pstmt. setString (9, "402888634f5d7f28014f62f415af1268"); pstmt. setString (10, "NONE"); pos ++; pstmt. addBatch (); pstmt. s EtString (1, UUID. randomUUID (). toString (). replaceAll ("-", ""); pstmt. setString (2, checkEndTimeStr); pstmt. setTimestamp (3, new Timestamp (checkEndTime. getTime (); pstmt. setString (4, checkEndTimeStr. substring (0, 4); pstmt. setString (5, checkEndTimeStr. substring (4, 6); pstmt. setString (6, checkEndTimeStr. substring (6, 8); pstmt. setString (7, checkEndTimeStr. substring (0, 8); pstmt. setString (8, result. GetString (1); pstmt. setString (9, "402888634f5d7f28014f62f415af1268"); pstmt. setString (10, "NONE"); pos ++; pstmt. addBatch (); if (pos % 10000 = 0) {long sj = (new Date (). getTime ()-t1.getTime ()/1000; pstmt.exe cuteBatch (); conn. commit (); System. out. println ("insert" + pos + ", in use" + sj + "seconds") ;}}} pstmt.exe cuteBatch (); conn. commit ();} catch (Exception e) {e. printStackTrace ();} finally {if (pst Mt! = Null) {try {pstmt. close () ;}catch (SQLException e) {e. printStackTrace () ;}} if (conn! = Null) {try {conn. close () ;}catch (SQLException e) {e. printStackTrace ();}}}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.