2014-04-25 52 views
0

我正在測試性能cassandra vs mysql,我不明白爲什麼mysql在同一個ubuntu中比cassandra更快。這是無聊嗎?注意:cassandra正在單個節點中運行。NoSQL cassandra問題

這裏我的測試和時間:

時報

[email protected]:~/x$ time python insert_mysql.py 

real 0m21.543s 
user 0m6.688s 
sys 0m2.016s 
[email protected]:~/x$ time python insert_cassandra.py 

real 1m15.157s 
user 0m14.293s 
sys 0m4.108s 
[email protected]:~/x$ 

卡桑德拉腳本

#!/usr/bin/python 

import cql 
import random 

db = cql.connect('localhost', 9160, 'mykeyspace', cql_version='3.0.0') 
cursor = db.cursor() 
i = 1 
while(i < 200001): 
    producte = random.randint(0,100) 
    color = random.randint(0,100) 
    preu = random.randint(100,1000) 

    cursor.execute('''INSERT INTO pintura (id, producte, color, preu) 
         VALUES (%s, %s, %s, %s)''' % (i, producte, color, preu)) 
    i += 1 

# Commit your changes in the database 
db.commit() 

# disconnect from server 
db.close() 

的MySQL腳本:

#!/usr/bin/python 

import MySQLdb 
import random 

# Open database connection 
db = MySQLdb.connect("localhost","root","pass","test") 

# prepare a cursor object using cursor() method 
cursor = db.cursor() 

#SQL query to INSERT a record into the table prova. 
i = 1 

while(i < 200001): 
    producte = random.randint(0,100) 
    color = random.randint(0,100) 
    preu = random.randint(100,1000) 

    cursor.execute('''INSERT INTO pintura (id, producte, color, preu) 
         VALUES (%s, %s, %s, %s)''' % (i, producte, color, preu)) 
    i += 1 

# Commit your changes in the database 
db.commit() 

# disconnect from server 
db.close() 

DDL MySQL的

mysql> create table pintura (
    -> id int primary key, 
    -> producte int, 
    -> color int, 
    -> preu int); 
Query OK, 0 rows affected (0.24 sec) 

mysql> create index i2 on pintura(producte); 
Query OK, 0 rows affected (0.12 sec) 
Records: 0 Duplicates: 0 Warnings: 0 

mysql> create index i1 on pintura(color); 
Query OK, 0 rows affected (0.07 sec) 
Records: 0 Duplicates: 0 Warnings: 0 

DDL的卡桑德拉

cqlsh:mykeyspace> create table pintura (
       ... id int primary key, 
       ... producte int, 
       ... color int, 
       ... preu int); 
cqlsh:mykeyspace> create index i1 on pintura (producte); 
cqlsh:mykeyspace> create index i2 on pintura (color); 
+1

蘋果和桔子。 ..兩個不同的dbs,兩個完全不同的接口機制(即使兩者之間的代碼本質上相同)等等...... –

+2

http://www.datastax.com/dev/blog/how-not-to-benchmark-cassandra – RussS

回答

2

一個標杆系統難以與標杆分佈式系統是額外的困難。你最有可能遇到了下列問題

  • 阻塞單線程組合請求
  • 全局解釋器鎖問題
  • 不飽和數據庫

More Detailed Information