24

I've been considering using Redis in a project that uses a lot of writes.

So, after setting it up on my server, I created a simple PHP script using Predis with a simple loop to add records. I also created a second script that does a similar thing, only on a MySQL table (InnoDB) using PHP's MySQLi.

I ran a 10k loop, a 100k loop and a 500k loop and MySQL beat Redis every single time. In fact, the more records I added, the faster MySQL was compared to Redis.

There's so much buzz (hype?) around Redis, that I want to believe I'm missing something here.

Please educate me :)

Thanks!

Here's my Predis code:

for ($i=0; $i<100000; $i++) {
    $predis->set('key'.$i, $i);
}

Here's my MySQLi code:

for ($i=0; $i<100000; $i++) {
    mysqli_query($db, "INSERT INTO test (`key`, `value`) VALUES ('key$i', $i)");
}
Ran Aroussi
  • 571
  • 1
  • 8
  • 11
  • 2
    just because redis is buzzword compliant by being no-sqlish doesn't mean it'll be fast. – Marc B Oct 29 '12 at 17:14
  • Is it possible that its not the way the database reacts but the way that php handles the insertion? – Adsy2010 Oct 29 '12 at 17:14
  • 1
    Does Redis keep an automatic index? Does your MySQL table have an index? Makes sure you're comparing the same thing. Indexes slow down inserts, but greatly improve reads. – Halcyon Oct 29 '12 at 17:15
  • see [Which noSQL database is best for high volume inserts / writes?](http://stackoverflow.com/questions/9447034/which-nosql-database-is-best-for-high-volume-inserts-writes) also http://stackoverflow.com/questions/3010224/mongodb-vs-redis-vs-cassandra-for-a-fast-write-temporary-row-storage-solution – Anthony Hatzopoulos Oct 29 '12 at 17:15
  • 3
    Might have something to do with: `Redis is a single-threaded server. It is not designed to benefit from multiple CPU cores. People are supposed to launch several Redis instances to scale out on several cores if needed. It is not really fair to compare one single Redis instance to a multi-threaded data store.` – Mr. Llama Oct 29 '12 at 17:16
  • 1
    Maybe you should first check if your code does what you think it does before jumping to conclusions. Some users were so nice and pointed with the finger on it, please fix your question. In it's current form it's far away from being constructive. - http://xdebug.org/docs/profiler – hakre Oct 29 '12 at 17:29
  • 4
    [Attention devops: "learn NoSQL" is not same as "learn no SQL"!](https://twitter.com/DEVOPS_BORAT/status/141368065110708224) – Anthony Hatzopoulos Oct 29 '12 at 17:30
  • 4
    There's a mistake in the benchmark code - but there _is_ a benchmark. I don't see the need to bully/ridicule the author. – AD7six Oct 29 '12 at 17:31
  • 10
    Yeah, the joke is funny, but @tuki deserves credit for at least making an effort to test. Lots of people make technology choices *without* testing. – Bill Karwin Oct 29 '12 at 17:33

1 Answers1

22

Comparing predis to mysqli is inappropriate

the mysqli extension - is an extension whereas predis is a php-client library. I.e. whereas mysqli is compiled code, predis is just plain php - extensions are faster.

A benchmark of the kind shown in the question primarily shows the performance loss of PHP code versus an extension.

Compare like with like

If you want to make a comparison of write performance - you'll need to compare to the php redis extension.

Community
  • 1
  • 1
AD7six
  • 63,116
  • 12
  • 91
  • 123
  • 7
    So... I've installed the (native?) [php redis extention](https://github.com/nicolasff/phpredis) and Redis results were 6 times faster than mysql on the 10k inserts, 3 times faster on a 50k inserts, and 1.5 on the 500k insers. Seems like the more inserts, the less difference there is. Thanks! – Ran Aroussi Oct 29 '12 at 21:44
  • 1
    ...And then there were transactions..... I can get 5k writes per second with Mysql/InnoDb- out of the box. Redis can't touch this. The only advantage I see using Redis would be to use it for frequently accessed/written data objects, such as sessions, to free up connections for Mysql. Redis and Mysql work very well together. There is no standalone winner or solution for scalable persistent storage. – FredTheWebGuy Apr 07 '13 at 18:23
  • Problem of growing hash tables. – Chibueze Opata Nov 03 '18 at 21:42