About Predis and benchmarks: why a pure-PHP Redis client anyway?

As some of you might know I'm the author and maintainer of Predis, a pure-PHP client library for Redis. When I started this project back in mid-2009 Redis was a very young yet promising NoSQL key-value store with only three client libraries available for PHP (one of which was a C-based extension that eventually led to phpredis) offering support only for the Redis commands implemented at that time, and plagued by many bugs. Fast forward to date, and both Predis and phpredis are now the two most used, stable and up-to-date clients in PHP-land among the bunch available. Although it's mostly a one-man project, I'm very proud of the work behind its development and thankful for the contributions received from the community.

So why am I writing this blog post? To cut it straight to the point, I think there's sometimes a little misconception about the very reason for which Predis exists nowadays and Aleksey's recent blog post is offering me a good opportunity to clarify things a bit. Don't get me wrong he made various valid points, but what has actually caught my attention and prompted me to write this post is the very introduction:

As some of you may know, I’m crazy about speed. So when I saw that people were happily using Predis as their choice of PHP client for Redis, I was a bit confused.

Why use a client written in PHP for something that should be ‘fast’ like Redis?

That kind of defeats the purpose - unless you don’t really care about response times and scalability. 

Predis was initially developed to fill the lack for a decent client library but turned into a more comprehensive solution allowing for maximum extensibility. In a sense, you may think of this library not only as a mere client for Redis but as a sort of framework (pass me the buzzword) with various building blocks that developers can leverage to create abstractions for features based upon Redis and expose them through a consistent interface. In my opinion a great example of such extensibility is the abstraction used to support Lua scripts exposing them as if they were common Redis operations such as GET or SET (and it works when using client-side sharding or master/slave replication too). Some parts were also reused to build a fully-asynchronous version of the client!

Obviously there's a price to pay for everything and, in our case, that price is a penalty in raw speed compared to a C-based extension due to the undeniable greater overhead of a pure-PHP implementation. You can mitigate part of this overhead by using PHP >= 5.4 (faster at method dispatching), an opcode cache (you should do that anyway on production servers) or even plugging in phpiredis for faster protocol (de)serialization, but in the end you are optimizing your stack on a single-server basis. You can have 5, 10, 100 servers hitting Redis for distributed operations: that's where Redis shines the best and that's why it's considered blazing fast. In such distributed scenarios, when one or more Redis instances are running on remote hosts, you will soon notice that most of the difference in speed is lost due to network round-trip times so you will be left for the most part with the inherent overhead of compiling the source code (or loading the cached opcodes) of Predis on each request. We've always been clear on what to expect out of Predis in this case and this is the reason why we have a FAQ about performances shipped along with the library. It's a matter of trade offs: you sacrifice a low overhead for the sake of flexibility.

But then again, is it possible to use Predis when you also need decent overall performances or scalability? Depending on your definition of "decent performances" in the context of your application and provided a correct setup and architecture, yes. I personally know of a few high-load web sites using Predis, each one with a different reason behind their choice. Sure, if you don't need fancy features and you only have one server performing requests against Redis running on the localhost then you would probably prefer to stick with phpredis thanks to its lower overhead, but that doesn't mean being able to scale. Is Predis better than phpredis, or the other way around? Simply put, they are two solutions to the same problem and both have their different strong and weak points. In the end you are the one to decide based on your needs but, more importantly and as Aleksey concluded, don't base your decisions on assumptions. And, I'd just like to add, not even on general benchmarks.


Puoi scrivere un commento oppure inviare un trackback dal tuo sito.

23 commenti a “About Predis and benchmarks: why a pure-PHP Redis client anyway?”

  1. Totally agree - performance isn't an absolute quality, but rather is derived from your requirements. BTW - Predis is a great Redis client, thanks for creating it!

  2. Soccer (or football match) has a huge following across the world.

    Learning in layers, like singing a song top eleven Cash and token Generator reading a story about the
    same topic, touches upon different learning styles.
    Brood War Artificial Intelligence Project is recommended for Star
    - Craft fanatics who are tired of beating-up on computer generated opponents.

  3. Thank you for the auspicious writeup. It in fact was once a entertainment account it.

    Look complicated to far brought agreeable from you!
    However, how could we keep in touch?

  4. Very rapidly this web site will be famous among all blogging people,
    due to it's nice articles

  5. Hi, all is going perfectly here and ofcourse every one is sharing information, that's truly good, keep up writing.

  6. i like your this image it is fantastic and wonderfull i would like to see more in future thanks.

  7. These may either be caused by the process of baking or the quality of breadmaker itself.

    I hope you will learn from my mistakes, and avoid
    them. Make your appliances work for you, and
    not the other way around.

  8. com to see where they're at (there are many to choose from) to plan your expedition according to your
    abilities and stamina with the bike. Ten miles back to the truck
    is a long walk when pushing 200 pounds of meat on a bike.

    Consider it out for a day, and see what it can do in relation to what
    you can do with it.

  9. Quality articles is the secret to invite the users to visit the web site,
    that's what this web page is providing.

  10. Everyone loves what you guys tend to be up too. This type of clever
    work and coverage! Keep up the fantastic works guys I've added
    you guys to our blogroll.

  11. In today's world you can now have fully prepared gourmet meals with
    delivery service right to your door. Miami Delivery Food is Your Aid For a Healthy Lifestyle.
    Some of the most important features offered at the restaurant include catering,
    takeout and delivery.

  12. It's an awesome post in support of all the web visitors; they will obtain advantage from it I am sure.

  13. Pretty! This was an incredibly wonderful post. Many thanks
    for providing this info.

  14. Hi there it's me, I am also visiting this web site on a regular
    basis, this web site is genuinely pleasant and the people are genuinely sharing nice thoughts.

  15. Simply desire to say your article is as astonishing. The clearness in your post is
    just nice and i could assume you are an expert on this subject.
    Fine with your permission let me to grab your feed to keep
    up to date with forthcoming post. Thanks a million and please continue the enjoyable
    work.

  16. Other methods of segmentation are used in the UK car industry such
    as demographics or geographic. I followed Werner down the road, got past the rise, and
    flashed my lights at him. This article discusses how to pick
    the task tracking software for your small business.

  17. Fantastic beat ! I wish to apprentice at the same time as you amend your website, how could i
    subscribe for a blog website? The account helped me a applicable deal.

    I had been a little bit acquainted of this your broadcast provided vibrant transparent concept

  18. hi!,I really like your writing so a lot! percentage we keep up a
    correspondence extra approximately your post on AOL?
    I require a specialist in this area to unravel my problem.
    May be that's you! Looking forward to peer you.

  19. Usually I don't read article on blogs, however I would like to
    say that this write-up very pressured me to check
    out and do so! Your writing taste has been surprised me.
    Thank you, very great article.

  20. Thanks for sharing your thoughts. I really appreciate your efforts
    and I am waiting for your further write ups thanks once again.

  21. 250 outdoors roulette web sites trading card bot steam us
    to. occasions.

  22. Attractive section of content. I just stumbled upon your
    weblog and in accession capital to say that I acquire in fact loved account your
    weblog posts. Anyway I will be subscribing to your
    augment and even I fulfillment you access constantly fast.

  23. Good day! I could have sworn I've been to this website before but after reading through some of the post I realized it's new to me.
    Anyways, I'm definitely glad I found it and I'll be
    bookmarking and checking back often!

Lascia un commento

Puoi utilizzare i seguenti tag XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>