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.

About to buy a DSC-RX100? Sony will announce its successor soon.

NOTE: this post is unusual for my almost-abandoned blog: it’s written in English instead of Italian and it’s about photography instead of software development or computer programming. Think of it as an experiment (or an attempt) to resume blogging.

As an happy owner of the DSC-RX100 I can’t deny that the news that Sony is about to announce a revised version of this high-end and enthusiast-oriented compact camera on 27th June (namely the DSC-RX100M2) has caught my attention. Actual details about this camera come from its recently leaked Japanese user manual. The great Sony Alpha Rumors blog spotted the rumor first and they recently confirmed it by publishing a bullet-point list of changes extracted from the above mentioned manual, I simply reused their list in this post to add my own considerations but credits for the actual news go to them.

Let’s start with the list of improvements of the DSC-RX100M2:

  1. Exmor R (BSI) sensor
    It sports the same size and resolution of the previous Exmor CMOS sensor (1″ and ~20 megapixels) but that R indicates it’s now back-illuminated. This may be nice news but the BSI technology is said to be mostly useful on sensors with a photosite size equal or less than 1.75µm (usually on 1/2.3″ sensors or smaller) while the size of the photosites of the RX100 is 2.4µm. I guess we can’t really say anything without seeing the actual RAW output first.
  2. Wi-Fi 802.11b/g/n
    This is not something I miss and I’d be inclined to classify this addition as typical P&S gadgetry, unless it allows for some kind of remote shutter release control of some kind, but I highly doubt it and I don’t see any indication of it.
  3. NFC
    I suppose this is solely meant to easily configure Wi-Fi connectivity for transferring photos to other devices such as smartphones. See above.
  4. Multi Interface Shoe and EVF support
    The MIS is a proprietary camera hotshoe system (21+3 pin) introduced by Sony in late 2012. Besides the dedicated Sony accessories, it can drive ISO flashes. It will also make it possible to use an external electronic view finder which is definitely a nice addition albeit the recommended retail price of $/€ 449.99 for the FDA-EV1MK (the same EVF for both the DSC-RX1 and DSC-HX50V) does hurt.
  5. Mini-HDMI has been moved from bottom to side, next to Micro-USB
    Surely OK, actually they should have positioned it like that since start, but how many times do you film/shoot with the camera while attached to a TV?
  6. Improved battery life, from 330 to 350 shots (CIPA)
    Even slight improvements are yays in the battery life department to me, but I can easily get a full day of shooting with the current RX100 and I prefer to have a spare battery with me anyway, so it’s not something that would affect me much in practice. The battery remained the same NP-BX1 which is good.
  7. ISO starts from 100 instead of 125
    I suppose they are referring to native ISO since the current RX100 can go as low as ISO 80 and 100 through expansion.
  8. Control ring can be set to smooth or click
    This improvement is big if you listen to most of the complaints over the internet about the control ring being clickless, which makes setting certain parameters such as ISO levels almost impossible without looking at the display if you have sounds turned off as I do. Luckily for me I like having the control ring assigned to manual focus operations where a smooth ring is actually better, so I’m not affected that much.
  9. Movie button can be disabled
    The dedicated movie button is handy and it proved to be so in a few real-life occasions, but sometimes it can be accidentally pressed. It happened a couple of times to me, but I still prefer to have it enabled to catch those unexpected moments instead of having to manually switch the camera to video mode which takes more time.
  10. 24p option for movies
    The original RX100 is already quite capable for shooting videos but having the added ability to record them in 24p is nice.
  11. White balance bracketing
    This is hardly useful when capturing images in the RAW format as you can adjust the WB later, but when shooting with multi-shot noise reduction or automatic HDR (both are only able to output JPG files for obvious reasons) this can be useful. Personally I’d have vastly preferred a more flexible exposure bracketing system than the current one which uses 3 exposures at only 0.3EV or 0.7EV intervals.
  12. Improved in-camera battery recharge times
    The charging current has been increased from 0.5A to 1.5A (approaching the 1.89A limit of the NP-BX1 battery), this should translate to 3 times faster charging times. While 99% of the time I use an external battery charger which offers faster charges, having the ability to charge the battery in-camera via USB is still useful and being able to do it faster is great.
  13. Tilt screen
    This is a great addition with the downside of making the camera slightly thicker (only 2.4mm), but that shouldn’t affect by much its jeans-pocketabily. The tilt system being used looks similar to the one adopted for the NEX-3N.
  14. Weight increased from 240g to 281g
    Finally, this is the price to pay for these physical improvements in terms of weight.

Now let’s see what didn’t make it in this revision compared to what people kept whining about:

  1. First of all, for those wanting both a wider lens but faster at the telephoto end it’s been confirmed that such a thing won’t happen: the lens is still a Vario-Sonnar T* 28-100mm (35mm equiv.) f1.8/4.9. Honestly I think far too many people keep demanding the impossible in terms of lens performances out of such a compact package. It’s most likely impossible to achieve a wider lens (many ask for 24mm!) keeping its f1.8 capabilities when the original RX100 already suffers from soft edges at 28mm due to barrel distortion corrections, and a faster lens at telephoto would surely require a different disposition of the optical groups. I’m also ignoring absurd requests for powerful zoom capabilities going up to say 140mm. At this point, and with a sensor of that size, almost nothing can be sensibly improved in terms of lens performances without affecting the whole package size.
  2. No integrated GPS. I find it useless anyway as it adds burden to the battery, personally I’m more than satisfied with using my TranSystem iBlue 747A+ GPS logger (now superseded by a newer model) to log all of my trips: I keep it always on when out for the whole day up to five days without worrying about battery, it’s fast to lock satellites and it’s probably way more precise than any built-in GPS. The obvious downside is that you must manually synchronize the internal camera time with the GPS time (you actually need to do that only once in a while) and you must geotag your shots later, but GeoTag makes it easy to do that in bulk from a GPX file and can write EXIF data to JPG, RAW files of various vendors and XMP files.
  3. On-sensor phase-detect autofocus. That’s simply not gonna happen, not even the DSC-RX1 has it.
  4. No hand grip or rugged surface for a more secure handhold. This can be easily worked around using third-party accessories, personally I don’t feel the need for it.
  5. No signs of the new JPEG engine that promises an improved compression quality. This engine will debut on Sony’s new Xperia flagship device (C680X code-named Honami) and will also be used on cameras starting with the SLT lineup through a firmware update. I find the current JPEG engine used by Sony to perform poorly compared to the output generated by other vendors.

All in all some of the improvements over the original DSC-RX100 are nice, but as a whole they are probably not worth the upgrade for anyone already owning it as they seem to be mostly targeted to satisfy those finding this camera lacking due to the absence of a tilt screen or an EVF-capable hotshoe.

Personally I’d be more interested in the new sensor if it proves to yield higher SNR ratios translating to visibly better outputs in low-light conditions and with less noise at high ISO levels, but I guess this is unlikely happen to an appreciable degree (we won’t get a whole stop of advantage). I find it very disappointing that the maximum shutter speed remained at 1/2000th second making wide apertures in strong sunlight a bit problematic, especially since there’s no built-in ND filter. Also, the EB is still limited to 3 exposure at 0.3EV or 0.7EV intervals.

Conclusions? Revision or not, the DSC-RX100 (with its flaws and compromises, just like any camera) provides the best IQ in such a pocketable package and competition has yet to announce a product comparable when combining performances and size.

Succede solo il primo Aprile (ormai annualmente)

Yao Ming Face

Succede solo il primo Aprile (immancabilmente)

Troll Face

Succede solo il primo Aprile (la vendetta)

E’ il primo Aprile no? Pensavate che mi sarei dimenticato dell’appuntamento ormai annuale, preciso come un orologio Svizzero, con questo blog? :-) In effetti stavo per dimenticarmene, ma eccomi qui. Questa volta però niente elenchi puntati, toppo noiosi e sterili. Piuttosto sono indeciso se rompere questa tradizione, ormai consolidatasi, e iniziare a postare qualche messaggio sempre inerente alla programmazione ma molto più easy, per esempio un breve resoconto sull’ottimo evento NoSQL Day svoltosi settimana scorsa in quel di Brescia. Per altro, giusto che si sta parlando di NoSQL e visto che è quanto successo una mezz’ora prima di scrivere questo post, ho appena rilasciato una nuova versione di Predis, un client PHP per Redis. Cercherò di trattenermi dallo scrivere di più in questo post proprio per provare a convincermi a preparare qualche altro post successivo, anche se onestamente sarà difficile. Nel frattempo, se proprio ci tenete, sapete dove trovarmi :-)