2011-11-24 58 views
1

我使用MySQL(MyISA)。超过8M行的表。 'id'的主要索引。mysql push index into memory

我的应用表明:

first run: 55 req/sec, 
second run: ~120 req/sec, 
third run: ~1200 req/sec, 
fourth run: ~4500 req/sec, 
fifth run: ~9999 req/sec 

重启MySQL服务器再次同后。 启动数据库服务器后,如何将所有索引一次放入内存中?

在my.cnf

key_buffer_size=2000M 

代码示例:

now = datetime.datetime.now() 
cursor = connection.cursor() 
for x in xrange(1, 10000): 
    id = random.randint(10, 100000) # random first 10000 records for cache 
    cursor.execute("""SELECT num, manufacturer_id 
        FROM product WHERE id=%s LIMIT 1""", [id]) 
    cursor.fetchone()  

td = datetime.datetime.now() - now 
sec = td.seconds + td.days * 24 * 3600 
print "%.2f operation/sec" % (float(x)/float(sec)) 
+1

请参阅http://openquery.com/blog/cache-preloading-mysqld-startup – nos

回答

0

我觉得两个缓存是在这里工作。一个是索引缓存,可以预装LOAD INDEX INTO CACHE

另一个是query cache,我认为在这种情况下,这是获得最高性能的地方。 AFAIK无法预装任何mysql命令。

您可以做的是替换重新启动之前运行的最后N个查询。那些查询会弹出缓存。或者保留一些真实的查询文件在启动时运行。

+0

如果您想查看“QUERY-CACHE-independent”性能,可能需要添加'/ *! SQL_NO_CACHE * /'提示查询。这样你会看到索引缓存,页面预取或表缓存实际上在那里流行。 – Romain