简体   繁体   中英

Mysql InnoDB vs Mongodb write performance

I need to increment a counter each time a web page is rendered.

  • When I use mongodb to do that, I can do about 16000 writes per second on a 4 cores/8 threads CPU on a regular disk.

  • When I use Mysql InnoDB table, I can do only... 30 writes per second on regular disk or 200 writes on SSD !!

Because I have only one write per transaction (basically I have no other write to do after incrementing my counter for a same http request) Using autocommit to False and manually commit will not help.

The différence is that Mongodb flushes writes lazyly.

I tried to have Mysql buffering writes before flushing them to disk by setting these parameters into my.cf, but it did not helped :

innodb_buffer_pool_size = 1G
innodb_flush_method=O_DIRECT
innodb_log_file_size=100M
innodb_change_buffering=all
innodb_thread_concurrency=8

Is there a way to have faster mysql writes ?

If all you are doing is "increment a counter each time a web page is rendered" then I suggest you ditch the database for this altogether. Keep the counter purely in memory (for example via memcached ), and use a cronjob to dump it to disk every 10 mins to keep a more permanent record.

If you're recording more than just a counter and want to use a database, consider using the MySQL MEMORY storage engine ( https://dev.mysql.com/doc/refman/5.0/en/memory-storage-engine.html ).

CREATE TABLE t (i INT) ENGINE = MEMORY;

The table will be kept in memory so will be much faster than a disk based table. You'll just need a script to do a manual 'flush' to disk (eg mysqldump ) from time to time if you need the permanence.

innodb_flush_log_at_trx_commit = 2

Is the winner : 150x faster !!! on standard disk (will try on SSD later)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM