- 論壇徽章:
- 0
|
本帖最后由 villainl 于 2019-05-23 12:48 編輯
單條數(shù)據插入1萬次在虛擬化平臺耗時單條數(shù)據插入1萬次在物理機上耗時
批量插入1萬條數(shù)據的時間,虛擬平臺和物理機基本相同。
從后臺的監(jiān)控看,虛擬化平臺的IO,CPU,內存的占用都比較低。這方面還有什么優(yōu)化的空間嗎?
虛擬機配置: CentOS 6.5 VCPU: 2 NUMBER OF CORES PER VCPU: 7 MEMORY: 128GiB 數(shù)據庫500GB
10塊 300GB虛擬磁盤組成的3TB的VG
Table:
CREATE TABLE `test3` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`k` int(11) NOT NULL DEFAULT '0',
`c` char(120) NOT NULL DEFAULT '',
`pad` char(100) NOT NULL DEFAULT '',
PRIMARY KEY (`id`),
KEY `k_1` (`k`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Insert 語句:
def ordinary_insert(count):
start = time.time()
tmp_sql = "INSERT INTO `test3` (`k`, `c`, `pad`) VALUES (0, '34838736059-24362714610-75033330387-17863378665-80928638402-33892306210-78377564998-17324442332-39178876426-77334528413', 'AAA')"
temp_str=""
sql=""
for i in range(count):
temp_str = '11946195857-63616115598-80208325001-42313633529-35180183845-' + str(random.randint(1, count)) + '-' + str(i)
sql = tmp_sql.replace('AAA', temp_str)
cur.execute(sql)
#sql = sql.replace('AAA', '11946195857-63616115598-80208325001-42313633529-35180183845-' + str(random.sample(list, 1)) + '-' + str(i))
seconds = time.time() - start
print("單條SQL循環(huán)" + str(count) + "次,數(shù)據寫入耗時" + str(seconds))
output = sys.stdout
with open("result.txt", "a+") as f:
sys.stdout = f
print("單條SQL循環(huán)" + str(count) + "次,數(shù)據寫入耗時" + str(seconds))
sys.stdout = output
|
|