OSCache: You too can pretend you're competent!

Over the course of the last few days, I’ve been helping out Chris Miller with a big update to OSCache. Needless to say, I’ve formulated a few less than happy thoughts about the whole thing which I must now expunge forthwith.

I’ve never been a heavy oscache user. In fact, my usage of it has been very limited, and often wrapped around in a lot of custom code, rather far from the default usage/settings. The problem however is that most people completely abuse this library. OSCache users, brace yourselves, I’m about to be rather rude to you…

Idiots! If your project does not run well without OSCache, you should be utterly ashamed of yourself. It shows that you might well have a lovely design that’ll make bloggers everywhere swoon with admiration and want to have your babies, but it also means you don’t know the first thing about optimisation. OSCache simply hides the problem (rather effectively sometimes). Somehow, you forgot to think about the feelings of that poor bastard who hits an uncached page, or that hapless fool who goes to a page which needs to be refreshed. He’s a small lone voice out there, to be sure. He’s also probably somewhat lacking in confidence, and will probably blame his network connection first. Even if he does suspect foul play, he’ll refresh the page and lo and behold, it’s speedy the next time round, so he assumes it was his own fault somehow.

Well folks, the joke is up. The next time you go to a vaguely java related page and you notice huge differences in speed sometimes, it’s because you’re hitting on the ‘real’ page, the one which shows the full ugly truth of the careless disregard for performance that the developer feels. That selfsame developer who casually calls database queries in tight loops in the name of functionality. The one who will lecture you on the finer points of MVC design, the one who scoffs at scriptlets and likes all their code to be in XML, preferably parsed (or executed!) per request (naturally), with as much reflection as possible to impress their friends and family.

All OSCache does in these situations is simply encourage this needless cruelty to users. You’re sacrificing the one for the many. To you, it’s alright if some people die for the greater good, you probably approve of capital punishment even if it has a 50% rate of guilty convictions.

Of course, this is ignoring the fairly disturbing problems with OSCache itself. I personally am horrified that people would run such code on a production system. Does nobody care about scalability or uptime anymore? Clustering? Is everyone writing apps that have a few hundred hits a day on a good day? Here’s a brief rundown of some of the problems in the current ‘production’ release:

  • Disk cache grows indefinitely. You can remove cache entries all you want, once they’re on disk, they stay there.
  • HEAD requests are cached with the same keys as POST and GET requests in autogenerated keys. Guaranteed to entertain most users for a few seconds.
  • Careful selection of cache keys can allow you to write random files on the server, fun for the whole family.
  • An amusing collection of memory leaks.
  • Unit tests which haven’t run successfully for over a year.
  • Unit tests which do not run on any non-windows platform.
  • Cruel disregard for thread safety. Not even Satan can help you if two users request the same uncached content at the same time.
  • Bizarre classes which cannot be used at all (well, just CacheProperties).
  • Loggers created per instance, not transient so they’re merrily dumped across the network (with a few thousand messages in tow) if you’re foolish enough to be clustering sessions.
  • ServletContext placed in a session. I’m too stunned to even comment on that.

    There is a ray of sunshine (well, a blinding light shining down from the heavens, more like) though in the current CVS codebase. All the issues above have been fixed, and more goodies are on the way (along with a whole new set of shiny bugs to laugh about one day), so wipe your tears, life isn’t so bad. Sometimes good things happen to bad people. By all means, use oscache, it’ll give you that extra little performance hike, but it should not be the difference between a completely unusable site and a usable one.

  • 2 Responses to “OSCache: You too can pretend you're competent!”

    1. Cameron Says:

      Use Tangosol Coherence ;-)

    2. Anonymous Says:

      Shameless Cameron, marketing his own product. Shameless indeed!

      But yes, he’s right. Use tangosol :)

    Leave a Reply