Apache Authors: Liz McMillan, Carmen Gonzalez, Elizabeth White, Pat Romanski, Christopher Harrold

Related Topics: Java IoT, Industrial IoT, Microsoft Cloud, Open Source Cloud, Machine Learning , Apache

Java IoT: Article

Caching: Up and Down the Stack

Boston Web Performance Meetup Wrap-up

The other month I presented Caching Up and Down the Stack at the Boston Web Performance meetup. It was great to get the chance to present to the 60+ people who came out for the talk. Unsurprisingly, many of the people there knew a lot about caching in all of the different levels I touched on, and some great conversation developed.

I covered six of the major areas of caching available to web devs today. On the HTML / JS / CSS side, you can use client asset caches, full-page HTTP caches (like Varnish) and partial template caches. On the back end, you can use generated code caches, manually cache objects in memory or nearby services or even enable your database’s query cache (though, as the audience reminded me, if you’re using MySQL, just don’t. See below for why). Caching at each layer has advantages and disadvantages, and throughout, you’ll only be effective if you know what you’re caching, why you’re caching it and if you measure the improvement of doing so. If you want to know more, check out the slides on Slideshare.

Obviously, this is a huge topic, and I didn’t come anywhere close to doing it justice. The audience came up with several interesting points, both during and afterwards.

1. One of the first questions I got was about a comparison between a cached an uncached page load. I showed this graph:

The main takeaway from this is the drop in bandwidth. 500k isn’t a trivial amount to download, especially when spread over 20-odd files, and doubly so when on a mobile browser. That’s a great improvement when cached, but somebody asked, “Why did the number of requests change?” It turns out that specifying a file as cacheable doesn’t necessarily imply that a connection to the server is unnecessary. For instance, files with an etag header set will validate against the server, and the server will return a 304 Unmodified if the etag matches. On the other hand, if the Cache-Control header is set with “public” and an appropriate max-age directive, the content doesn’t have to be validated, and the browser may entirely eliminate the HTTP request.These days, this can actually be quite effective, as the ratio of time spent downloading content vs. establishing connections is lower than it has ever been. If you’ve got content that doesn’t change (because it’s versioned in the filename, for instance), set it as Cache-Control: public, max-age=large-number!

2. In the words of one wise audience member, “The MySQL query cache sucks. Never use it.” I don’t disagree. But why? Consider the following properties of this cache:

  • It only caches exact matches on queries.
  • It is invalidated every time anything in the table changes.

If you think about your data and access patterns, there’s a good chance one or both of these properties make the MySQL query cache unsuitable for production use. Few apps have large, static data sets and unpredictable but highly repetitive queries. In most cases, the query cache will spend its time in two states – cold and empty, or flushing itself. Neither will make your application appreciably faster.

Instead, consider caching objects at a coarser granularity once you’ve retrieved them from the DB, or consider adding a proper set of indices to ensure that common queries to your tables are quick.

3. Though I spent most of my time on object caching, I neglected to mention one of the most effective places to cache language objects: in memory on the machine it’s used on! Object caching is generally any type of caching that’s done by retrieving an object from a slower data store (that may involve an expensive computation), and storing the result in an easy-to-lookup place. While memcache in great for this, and has the advantage of scaling independently of your app itself, sometimes just stashing an object in a global dictionary can be the best solution. Plus, especially if the set is bounded or never changes, invalidation and cleanup can be as easy as waiting until your next deploy to reboot the app servers!

All in all, it was great to see everybody out, and I’m looking forward to the next Boston Web Performance Meet-up!

Related Articles

The 5 Critical Things You Need to Know to Assure Optimal Performance in the Cloud

QoS, Wherefore Art Thou

Solving Slow Database Performance In Java and MySQL

More Stories By TR Jordan

A veteran of MIT’s Lincoln Labs, TR is a reformed physicist and full-stack hacker – for some limited definition of full stack. After a few years as Software Development Lead with Thermopylae Science and Techology, he left to join Tracelytics as its first engineer. Following Tracelytics merger with AppNeta, TR was tapped to run all of its developer and market evangelism efforts. TR still harbors a not-so-secret love for Matlab-esque graphs and half-baked statistics, as well as elegant and highly-performant code. Read more of his articles at www.appneta.com/blog or visit www.appneta.com.

IoT & Smart Cities Stories
The platform combines the strengths of Singtel's extensive, intelligent network capabilities with Microsoft's cloud expertise to create a unique solution that sets new standards for IoT applications," said Mr Diomedes Kastanis, Head of IoT at Singtel. "Our solution provides speed, transparency and flexibility, paving the way for a more pervasive use of IoT to accelerate enterprises' digitalisation efforts. AI-powered intelligent connectivity over Microsoft Azure will be the fastest connected pat...
At CloudEXPO Silicon Valley, June 24-26, 2019, Digital Transformation (DX) is a major focus with expanded DevOpsSUMMIT and FinTechEXPO programs within the DXWorldEXPO agenda. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive over the long term. A total of 88% of Fortune 500 companies from a generation ago are now out of business. Only 12% still survive. Similar percentages are found throug...
As you know, enterprise IT conversation over the past year have often centered upon the open-source Kubernetes container orchestration system. In fact, Kubernetes has emerged as the key technology -- and even primary platform -- of cloud migrations for a wide variety of organizations. Kubernetes is critical to forward-looking enterprises that continue to push their IT infrastructures toward maximum functionality, scalability, and flexibility. As they do so, IT professionals are also embr...
CloudEXPO has been the M&A capital for Cloud companies for more than a decade with memorable acquisition news stories which came out of CloudEXPO expo floor. DevOpsSUMMIT New York faculty member Greg Bledsoe shared his views on IBM's Red Hat acquisition live from NASDAQ floor. Acquisition news was announced during CloudEXPO New York which took place November 12-13, 2019 in New York City.
In an age of borderless networks, security for the cloud and security for the corporate network can no longer be separated. Security teams are now presented with the challenge of monitoring and controlling access to these cloud environments, at the same time that developers quickly spin up new cloud instances and executives push forwards new initiatives. The vulnerabilities created by migration to the cloud, such as misconfigurations and compromised credentials, require that security teams t...
The graph represents a network of 1,329 Twitter users whose recent tweets contained "#DevOps", or who were replied to or mentioned in those tweets, taken from a data set limited to a maximum of 18,000 tweets. The network was obtained from Twitter on Thursday, 10 January 2019 at 23:50 UTC. The tweets in the network were tweeted over the 7-hour, 6-minute period from Thursday, 10 January 2019 at 16:29 UTC to Thursday, 10 January 2019 at 23:36 UTC. Additional tweets that were mentioned in this...
The term "digital transformation" (DX) is being used by everyone for just about any company initiative that involves technology, the web, ecommerce, software, or even customer experience. While the term has certainly turned into a buzzword with a lot of hype, the transition to a more connected, digital world is real and comes with real challenges. In his opening keynote, Four Essentials To Become DX Hero Status Now, Jonathan Hoppe, Co-Founder and CTO of Total Uptime Technologies, shared that ...
After years of investments and acquisitions, CloudBlue was created with the goal of building the world's only hyperscale digital platform with an increasingly infinite ecosystem and proven go-to-market services. The result? An unmatched platform that helps customers streamline cloud operations, save time and money, and revolutionize their businesses overnight. Today, the platform operates in more than 45 countries and powers more than 200 of the world's largest cloud marketplaces, managing mo...
When Enterprises started adopting Hadoop-based Big Data environments over the last ten years, they were mainly on-premise deployments. Organizations would spin up and manage large Hadoop clusters, where they would funnel exabytes or petabytes of unstructured data.However, over the last few years the economics of maintaining this enormous infrastructure compared with the elastic scalability of viable cloud options has changed this equation. The growth of cloud storage, cloud-managed big data e...
Your applications have evolved, your computing needs are changing, and your servers have become more and more dense. But your data center hasn't changed so you can't get the benefits of cheaper, better, smaller, faster... until now. Colovore is Silicon Valley's premier provider of high-density colocation solutions that are a perfect fit for companies operating modern, high-performance hardware. No other Bay Area colo provider can match our density, operating efficiency, and ease of scalability.