Tuesday, June 14, 2022
HomeWordPress DevelopmentMigrating from App Engine Memcache to Cloud Memorystore (Module 13)

Migrating from App Engine Memcache to Cloud Memorystore (Module 13)



Posted by Wesley Chun (@wescpy), Developer Advocate, Google Cloud

Introduction and background

The earlier Module 12 episode of the Serverless Migration Station video sequence demonstrated tips on how to add App Engine Memcache utilization to an present app that has transitioned from the webapp2 framework to Flask. At the moment’s Module 13 episode continues its modernization by demonstrating tips on how to migrate that app from Memcache to Cloud Memorystore. Transferring from legacy APIs to standalone Cloud providers makes apps extra transportable and gives a better transition from Python 2 to three. It additionally makes it doable to shift to different Cloud compute platforms ought to that be desired or advantageous. Builders profit from upgrading to fashionable language releases and acquire added flexibility in application-hosting choices.

Whereas App Engine Memcache gives a primary, low-overhead, serverless caching service, Cloud Memorystore “takes it to the subsequent stage” as a standalone product. Quite than a proprietary caching engine, Cloud Memorystore offers customers the choice to pick from a pair of open supply engines, Memcached or Redis, every of which gives extra options unavailable from App Engine Memcache. Cloud Memorystore is often extra value environment friendly at-scale, presents excessive availability, gives computerized backups, and so forth. On prime of this, one Memorystore occasion can be utilized throughout many functions in addition to incorporates enhancements to reminiscence dealing with, configuration tuning, and so forth., gained from expertise managing an enormous fleet of Redis and Memcached cases.

Whereas Memcached is extra just like Memcache in utilization/options, Redis has a a lot richer set of knowledge buildings that allow highly effective utility performance if utilized. Redis has additionally been acknowledged because the most beloved database by builders in StackOverflow’s annual builders survey, and it is an awesome ability to choose up. For these causes, we selected Redis because the caching engine for our pattern app. Nonetheless, in case your apps’ utilization of App Engine Memcache is deeper or extra advanced, a migration to Cloud Memorystore for Memcached could also be a greater possibility as a better analog to Memcache.

Migrating to Cloud Memorystore for Redis featured video


Performing the migration

The pattern utility registers particular person net web page “visits,” storing customer info comparable to IP tackle and consumer agent. Within the authentic app, the latest visits are cached into Memcache for an hour and used for show if the identical consumer repeatedly refreshes their browser throughout this era; caching is a one strategy to counter this abuse. New guests or cache expiration outcomes new visits in addition to updating the cache with the latest visits. Such performance have to be preserved when migrating to Cloud Memorystore for Redis.

Under is pseudocode representing the core a part of the app that saves new visits and queries for the latest visits. Earlier than, you possibly can see how the latest visits are cached into Memcache. After finishing the migration, the underlying caching infrastructure has been swapped out in favor of Memorystore (by way of language-specific Redis consumer libraries). On this migration, we selected Redis model 5.0, and we advocate the most recent variations, 5.0 and 6.x on the time of this writing, as the most recent releases characteristic extra efficiency advantages, fixes to enhance availability, and so forth. Within the code snippets under, discover how the calls between each caching programs are almost equivalent. The bolded traces characterize the migration-affected code managing the cached knowledge.

Switching from App Engine Memcache to Cloud Memorystore for Redis

Wrap-up

The migration coated begins with the Module 12 pattern app (“START”). Migrating the caching system to Cloud Memorystore and different requisite updates leads to the Module 13 pattern app (“FINISH”) together with an optionally available port to Python 3. To apply this migration by yourself to assist put together on your personal migrations, observe the codelab to do it by-hand whereas following alongside within the video.

Whereas the code migration demonstrated appears easy, probably the most vital change is that Cloud Memorystore requires devoted server cases. For that reason, a Serverless VPC connector can be wanted to attach your App Engine app to these Memorystore cases, requiring extra devoted servers. Moreover, neither Cloud Memorystore nor Cloud VPC are free providers, and neither has an “At all times free” tier quota. Earlier than transferring ahead this migration, test the pricing documentation for Cloud Memorystore for Redis and Serverless VPC entry to find out value concerns earlier than making a dedication.

One key improvement which will have an effect on your determination: In Fall 2021, the App Engine staff prolonged help of lots of the legacy bundled providers like Memcache to next-generation runtimes, that means you might be not required emigrate to Cloud Memorystore when porting your app to Python 3. You’ll be able to proceed utilizing Memcache even when upgrading to three.x as long as you retrofit your code to entry bundled providers from next-generation runtimes.

A transfer to Cloud Memorystore and at present’s migration strategies shall be right here if and if you determine that is the course you need to take for your App Engine apps. All Serverless Migration Station content material (codelabs, movies, supply code [when available]) may be accessed at its open supply repo. Whereas our content material initially focuses on Python customers, we plan to cowl different language runtimes, so keep tuned. For extra video content material, try our broader Serverless Expeditions sequence.



RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments