Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Caching Over Mybatis – Summary of Approaches

DZone's Guide to

Caching Over Mybatis – Summary of Approaches

· Big Data Zone ·
Free Resource

Hortonworks Sandbox for HDP and HDF is your chance to get started on learning, developing, testing and trying out new features. Each download comes preconfigured with interactive tutorials, sample data and developments from the Apache community.

This article presents a summary of the four Proof of Concepts described in the article 4 Hands-On Approaches to Improve Your Data Access Layer Implementation  and contains a retrospective of the four implementations, with a comparison table of their key features.

Code for implementations can be accessed at https://github.com/ammbra/CacherPoc .

Before analyzing the results we obtained through the four implementations, I would like to remind the goal of these articles: to illustrate through usage the behavior of MyBatis cache implementations with Ehcache, Hazelcast, Memcached and OSCache.  A more complex view of CacherPOC and its associates is presented below:


and the online view of the application:


I am going to detail my opinions about the four libraries, after concept's implementation.

All the used libraries (Ehcache, OSCache, Memcached and Hazelcast) support in memory data management, transactions and have the following attributes:

  • atomicity
  • consistency
  • isolation
  • durability (durability of data handling as ACID integrity model specifies)
  • horizontal scalable
  • automatic deletion after expiration
  • embedable
  • open source
  • function on cross-platform operating systems

Also, let's investigate what differentiate them in terms of features:

Characteristic

Ehcache

Hazelcast

Memcached

OSCache

The language the software is written in

Java

C#, Java, .net, C++

C#

Java

Database model

Key-Value

Distributed data structure

NoSQL

Schema-less

Key-Value

Distributed data structure

NoSQL

Schema-less

Publish/Subscribe

Key-Value

Key-Value

Integrity model

ACID

ACID

MVCC

Serializable

ACID

ACID

Maximum size of a single value

8GB

10MB

1MB

?

Conditional entry updates

Yes

Yes

No

No

Composite key

Yes

Yes

No

No

Locking model

Optimistic Locking

Optimistic Locking

Pessimistic Locking

Distributed Locking

Lock Free Model

?

Data Storage

Volatile Memory

File System

Volatile Memory

Relational DB

Volatile Memory

Volatile Memory

Backup Functionality

Good

Good

Basic

?

Second level caching

Yes

Yes

No

No

Cloud platform support

?

Amazon EC2

?

?

Map and reduce

?

Yes

No

?

? - could not be determined

Based on features list, we can choose a caching implementation. But the most important evidence came from CacherPOC project: the results obtained when Amdhal's law was applied.

Amdhal's law is 

where P is proportion speed up and S is speed up.

Below are listed the results obtained by :

  • Ehcache implementation : 2 times system speedup
  •  Hazelcast implementation : 1.96 times system speedup
  • Memcached implementation: 2.083 times system speedup
  • Oscache implementation: 2.028 times system speedup

The results obtained show Memcached as  the winner of caching over mybatis competition, but do not forget that it was tested a simple select; have in mind that complex operation might show another framework to be more suitable for caching over MyBatis. My recommendation would be: download CacherPOC, modify with the complex operations that you should test and check your own system speedup by using Amdhal's law. CacherPOC represents the base of complex future system tests.

Learn more from:

Hortonworks Community Connection (HCC) is an online collaboration destination for developers, DevOps, customers and partners to get answers to questions, collaborate on technical articles and share code examples from GitHub.  Join the discussion.

Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}