MariaDB Performance Test - goddes4/python-study-wiki GitHub Wiki

Python Connector ์„ค์น˜

# pip install --egg mysql-connector-python-rf

ํ…Œ์ŠคํŠธ ์ฝ”๋“œ

from mysql.connector import connect
import time

p_list = []
current_time = time.time()
for i in range(100000):
    p_list.append(
        (
            "Joshuaxx{}".format(i), "layoutyy{}".format(i),
            "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
            "12345678901234567890123456789012345678901234567890", "nfc", current_time,
        ))

conn = connect(user='root', password='rainus!@#', host='localhost', database='infortab')
cur = conn.cursor()
cur_time = time.time()

cur.executemany('REPLACE INTO t_product (pr_code, layout_id, pr_info, page, nfc, last_modified) VALUES (%s, %s, %s, %s, %s, %s)', p_list)
diff_time = time.time() - cur_time

print('diff time : ', diff_time)
cur.close()
conn.commit()
conn.close()

Insert ํ•˜๊ธฐ์ „์— DB ์„ค์ •

# SET GLOBAL max_allowed_packet = 1073741824;

10๋งŒ๊ฐœ ๋ฐ์ดํ„ฐ ์ž…๋ ฅ

insert = 3.1s
replace = 10.94s

๊ฐ๊ฐ ๋‹ค๋ฅธ ํ…Œ์ด๋ธ”์— 10๋งŒ๊ฑด ์ž…๋ ฅ ์†๋„ ์ธก์ • (REPLACE INTO)

1 stire : 10.45s
2 store : 10.47s
3 store : 11.18s
4 store : 11~13s
5 store : 15~17s
6 store : 17~19s
7 store : 22~24s
8 store : 24~26s

โ€ป ์—ฐ๊ฒฐ๋‹น Thread Pool์—์„œ Thread๋ฅผ ํ• ๋‹น ๋ฐ›์•„ ์ฒ˜๋ฆฌ

1000๋งŒ๊ฑด ํŒŒ์ผ ์ƒ์„ฑ (์†๋„ : 15.37s, ์šฉ๋Ÿ‰ : 2.4G)

import time
p_list = []
current_time = time.time()
with open('/tmp/test.csv', 'w') as f:
    for i in range(10000000):
        f.write("Joshuaxx{},layoutyy{},123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890,12345678901234567890123456789012345678901234567890,nfc,{}\n".format(i, i, current_time))
diff_time = time.time() - current_time

print('diff time : ', diff_time)

ํŒŒ์ผ ์ž…๋ ฅ ๋ฐ ์ถœ๋ ฅ (/tmp ์—์„œ ์ˆ˜ํ–‰)

# SELECT  * FROM t_product INTO OUTFILE '/tmp/test.csv'
# LOAD DATA INFILE '/tmp/test.csv' INTO TABLE t_product FIELDS TERMINATED BY ',';
๊ฒฐ๊ณผ : 1000๋งŒ๊ฑด 107.07์ดˆ

๋ ˆ์ฝ”๋“œ ์ˆ˜ ์กฐํšŒ

# SELECT COUNT(*) FROM ํ…Œ์ด๋ธ”
MyISAM ์€ ํ…Œ์ด๋ธ”๋ณ„ ๋ ˆ์ฝ”๋“œ์ˆ˜๋ฅผ ๊ธฐ์–ตํ•˜๊ณ  ์žˆ์–ด์„œ ๋น ๋ฆ„
innoDB ๋Š” ๋А๋ฆผ (ํŠธ๋ฆฌ๊ฑฐ๋ฅผ ์ด์šฉํ•œ ์นด์šดํŠธ ํ…Œ์ด๋ธ” ๊ณ ๋ ค)

๋ ˆ์ฝ”๋“œ ์žˆ๋Š”์ง€๋งŒ ์ฒดํฌ ํ• ๊ฒฝ์šฐ

# SELECT 1 FROM ํ…Œ์ด๋ธ” LIMIT 1

์นด์šดํŠธ ํ…Œ์ด๋ธ” (ํŠธ๋ฆฌ๊ฑฐ ์‚ฌ์šฉ)

# CREATE TABLE t_product_cnt (cnt INT UNSIGNED NOT NULL);
# INSERT INTO t_product_cnt VALUES (0);

# DELIMITER |
# CREATE TRIGGER t_product_insert AFTER INSERT ON t_product FOR EACH ROW BEGIN
   UPDATE t_product_cnt  SET cnt=cnt+1;
END|

# CREATE TRIGGER t_product_delete AFTER DELETE ON t_product FOR EACH ROW BEGIN
   UPDATE t_product_cnt SET cnt=cnt-1;
END|

# DELIMITER ;