Training Webinar: Enterprise application performance with distributed caching

29
Enterprise Application Performance Distributed Caching Tito Moreira Solution Architect - Experts Team

Transcript of Training Webinar: Enterprise application performance with distributed caching

Page 1: Training Webinar: Enterprise application performance with distributed caching

Enterprise Application PerformanceDistributed Caching

Tito MoreiraSolution Architect - Experts Team

Page 2: Training Webinar: Enterprise application performance with distributed caching

Performance Hurdles

• Application code○Slow Queries / too many accesses to database○Slow Extensions○Large ViewState / Session

• Infrastructure○Database○Network

Page 3: Training Webinar: Enterprise application performance with distributed caching

Caching helps, right?

Page 4: Training Webinar: Enterprise application performance with distributed caching

Caching helps, right?There are only two hard things in Computer Science: cache invalidation and naming things.

-- Phil Karlton

Page 5: Training Webinar: Enterprise application performance with distributed caching

Out-Of-the-Box Caching in OutSystems

• Queries• Actions• WebBlocks• Screens

Page 6: Training Webinar: Enterprise application performance with distributed caching

Out-Of-the-Box Caching in OutSystems

in-memory process(local server cache)

• Queries• Actions• WebBlocks• Screens

Page 7: Training Webinar: Enterprise application performance with distributed caching

Considerations when using local server caching• It shares resources (memory) with other apps in the same

OutSystems Front End • Data in cache is not consistent across ≠ servers• Not fitted to store hundreds of Megabytes of data• It’s entirely managed by OS platform

○ Developers cannot control the cache entry keys ○ It is not possible to store local variables, e.g. lists of Structures ○ Cache invalidation mechanisms is somehow limited

• Does not escalate well with the number of Servers○ First hit in each local Server cache is always a “Miss”, however

this can be dealt with using Warm-up procedures.

Page 8: Training Webinar: Enterprise application performance with distributed caching

Data consistency using local server caching

Page 9: Training Webinar: Enterprise application performance with distributed caching

What is Distributed Caching?

Page 10: Training Webinar: Enterprise application performance with distributed caching

Distributed Cache concepts

• Stores the cache on dedicated infrastructure resources○ Distributed cache has different scalability needs

• Maintains the infrastructure server caches synchronized○ Every server in the distributed cache infrastructure should have the

same data for a cache entry. • Makes the cached data remotely available to all Front-Ends in

a transparent way○ Front-Ends don’t have any knowledge about the distributed cache

infrastructure• It is complementary to the OutSystems built-in cache

○ Distributed cache does not replace the local cache, it is used in addition to it in order to overcome certain local cache limitations inherent to that approach (e.g. cache data coeherence).

Page 11: Training Webinar: Enterprise application performance with distributed caching

General Distributed Cache Infrastructure

Load BalancerUser

Cache protocol (over TCP/IP)

HTTP RequestsInternal Network

(haProxy or other)

Page 12: Training Webinar: Enterprise application performance with distributed caching

Patterns to Populate a Distributed Cache

• On Demand / Cache Aside / Read-Through○ The application tries to retrieve data from cache, when there’s a

“miss” the application is responsible for storing the data in the cache so it will be available next time.

○ To implement Write-Through the Cache should be updated whenever the records are.

MyApp (UI) DataServices_CS

DB

Distributed Cache infrastructure2

1

3Encapsulates Entities,providing Read or Write user Actions

Consumes data related Actions

Tries to read from cache

On cache miss, data is read from DB

CacheConnector4

Data is updated in Cache, to be available on next access

Page 13: Training Webinar: Enterprise application performance with distributed caching

Patterns to Populate a Distributed Cache

• Background Data Push○ Timer background Action “pushes” data into the distributed

cache on a regular schedule. Any consumer application pulls the same data from the cache without being responsible for updating the cache data.

MyApp (UI) DataServices_CS

DB

Distributed Cache infrastructure2

1

3Encapsulates Entities, providing Read or Write user Actions

Consumes data related Actions

Updates cache on a regular interval

CacheSync_CS

Writes should invalidate cache!

CacheConnector

Page 14: Training Webinar: Enterprise application performance with distributed caching

Patterns to Populate a Distributed Cache

On-Demand Background Data Push

High frequency of data change

Good(cache can be updated immediately on the

Write use Action)

Bad(background process makes high

frequency cache updates not feasible)

Exposed Write operations

Good(cache is updated on demand)

Bad(there might be conflicts between Write

operations and background process - locking required)

Performance on first access

Bad(cache miss requires a DB read and cache

update)

Good(there shouldn’t be any cache misses - all

data should be cached ahead)

Cache of large blocks of Data

Bad(small amounts of data only, since caching

is done synchronously on cache misses)

Good(caching of big chunks of data is done

asynchronously)

Page 15: Training Webinar: Enterprise application performance with distributed caching

Benefits from using Distributed Caching

So what? How can I benefit from it?• Access cached data from anywhere

○ Actions, Extensions, external applications, etc• Get stats about what is stored • Relief data from Session• Store significant amounts of pre-processed data

○ Yes, Gigabytes of Query data!• Load cache data from background processes

○ It opens an entire spectrum of initialization possibilities• It’s easier to scale cache Servers than DB servers

Page 16: Training Webinar: Enterprise application performance with distributed caching

Distributed Cache

• Get stats about what is stored (most providers)

Page 17: Training Webinar: Enterprise application performance with distributed caching

When to use Distributed Cache?

Page 18: Training Webinar: Enterprise application performance with distributed caching

When to use Distributed Caching

• Don’t use it if:○There are just a few Front End Servers (1 or 2)○Your Apps won’t have a significant amount of traffic○Your Apps don’t suffer from performance issues ○You want to replace OutSystems local cache function

entirely■ Distributed Cache is a complementary component, and should be

used in very specific scenarios!

Page 19: Training Webinar: Enterprise application performance with distributed caching

When to use Distributed Caching

• You should consider using it if:○You have more than 3 Front End Servers and you might

need to scale even further○You have public-facing Web apps that display “static”

data. ○Your data changes often making local caches invalid○You need 100% control over the cache○You need to share state between Servers without using

Database or Session

Page 20: Training Webinar: Enterprise application performance with distributed caching

Recommended way to deploy a Distributed Cache

Page 21: Training Webinar: Enterprise application performance with distributed caching

Distributed Cache deploy recommendations• Don’t install Distributed Cache services in OutSystems

servers• Use a different infrastructure for the Distributed Cache

servers• If in the OS Cloud, it’s advised to use AWS Elastic Cache in

the same VPC• Plan for the Memory and CPU requirements of the Distributed

Cache servers○ Requests/sec, Reads/Writes, Size of cached data

• Keep the Distributed Cache servers in the same network as the OS servers○ Without firewalls, proxies or similiar in between ( < latency)

Page 22: Training Webinar: Enterprise application performance with distributed caching

Managing Distributed Cache

• Data remains cached even after a release (different infrastructure)○ Not managed by Lifetime (Lifetime plugin for Cache purge?)

• Cached data should to be purged whenever there is a release○ Data model might have changed○ Data from previous release might be incompatible with latest release○ Cached data requirements might be different for the new release

• Cached data initialization is possible with external processes• Distributed Caching locking mechanisms depend on

implementation (Redis ≠ Memcached)• Distributed Caching resources should be monitored

independently of OS Front-Ends

Page 23: Training Webinar: Enterprise application performance with distributed caching

dmCachea Distributed Cache Connector

Page 24: Training Webinar: Enterprise application performance with distributed caching

Introducing dmCache

• dmCache is a Forge component that:○ Provides actions to store/read OS data types and Records○ Abstracts the developer from the Distributed Cache protocol and

implementation○ Helps the developer generate Cache entry keys:

■ Global (viewable by all applications)■ Application■ Session■ Web Request

Page 25: Training Webinar: Enterprise application performance with distributed caching

Using dmCache

Page 26: Training Webinar: Enterprise application performance with distributed caching

Supported Cache Providers in dmCache

• Memcached• Redis• Couchbase• AWS Elastic Cache• Azure Redis Cache

Page 27: Training Webinar: Enterprise application performance with distributed caching

dmCache in Action!(Demo)

Page 28: Training Webinar: Enterprise application performance with distributed caching

We’ll be back in 5 min to answeryour questions

Page 29: Training Webinar: Enterprise application performance with distributed caching

Thank you!