DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Scalable Data Grid Using Apache Ignite
  • Providing Enum Consistency Between Application and Data
  • What Developers Need to Know About Table Geo-Partitioning
  • Implement a Distributed Database to Your Java Application

Trending

  • Streamlining Event Data in Event-Driven Ansible
  • How to Practice TDD With Kotlin
  • Emerging Data Architectures: The Future of Data Management
  • Understanding Java Signals
  1. DZone
  2. Data Engineering
  3. Data
  4. 8 Things Every Developer Should Know About Apache Ignite Caching

8 Things Every Developer Should Know About Apache Ignite Caching

In this post, we go over how you should properly implement caching in your Ignite-based app to avoid any development headaches.

By 
Shamim Bhuiyan user avatar
Shamim Bhuiyan
·
Updated Mar. 16, 20 · Tutorial
Likes (13)
Comment
Save
Tweet
Share
30.5K Views

Join the DZone community and get the full member experience.

Join For Free

Any technology, no matter how advanced it is, will not be able to solve your problems if you implement it improperly. Caching, precisely when it comes to the use of a distributed caching, can only accelerate your application with the proper use and configurations of it. From this point of view, Apache Ignite is no different, and there are a few steps to consider before using it in the production environment.

In this article, we describe various technics that can help you to plan and adequately use Apache Ignite. 

  1. Do proper capacity planning before using Ignite clusters. Do paperwork for understanding the size of the cache, number of CPUs or how many JVMs will be required. Let’s assume that you are using Hibernate as an ORM in 10 application servers and wish to use Ignite as an L2 cache. Calculate the total memory usages and the number of Ignite nodes you need for maintaining your SLA. An incorrect number of the Ignite nodes can become a bottleneck for your entire application. Please use the Apache Ignite official documentation for preparing a system capacity planning.

  2. Select the best deployment option. You can use Ignite as an embedded or a real cluster topology. All of them contain a few pros and cons. When Ignite is running in the same JVM (in embedded mode) with the application, the network roundtrip for getting data from the cache is minimum. However, in this case, Ignite uses the same JVM resources along with the application which can impact the application's performance. Moreover, in the embedded mode, if the application dies, the Ignite node also fails. On the other hand, when an Ignite node is running on a separate JVM, there is a minimal network overhead for fetching the data from the cluster. So, if you have a web application with a small memory footprint, you can consider using Ignite nodes in the same JVM.

  3. Use on-heap caching for getting maximum performance. By default, Ignite uses Java off-heap for storing cache entries. When using off-heap to store data, there is always some overhead of de/serialization of data. To mitigate the latency and get the maximum performance you can use on-heap caching. You should also take into account that Java heap size is almost limited and there is a GC (Garbage collection) overhead whenever you're using on-heap caching. Therefore, consider using on-heap caching whenever you are using a small limited size of a cache, and the cache entries are almost constants.

  4. Use Atomic cache mode whenever possible. If you do not need strong data consistency, consider using atomic mode. In atomic mode, each DML operation will either succeed or fail, and neither read nor write operations will lock the data. This mode gives better performance than the transactional mode. An example of using an atomic cache configuration is shown below.

<property name="cacheConfiguration">
    <list>
        <bean class="org.apache.ignite.configuration.CacheConfiguration">
            <property name="name" value="testCache" />
            <property name="atomicityMode" value="ATOMIC" />
        </bean>
    </list>
</property>

5. Disable unnecessary internal events' notifications. Ignite has a rich event system to notify users/nodes about various events, including cache modification, eviction, compaction, topology changes, and a lot more. Since thousands of events per second are generated, it creates an additional load on the system. This can lead to significant performance degradation. Therefore, it is highly recommended to enable only those events that your application logic requires.

<bean class="org.apache.ignite.configuration.IgniteConfiguration">
    <!-- Enable events that you need and leave others disabled -->
    <property name="includeEventTypes">
        <list>
            <util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_STARTED"/>
            <util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_FINISHED"/>
            <util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_FAILED"/>
        </list>
    </property>
</bean>

6. Turn off backup's copy. If you are using a PARTITIONED cache and the data loss is not critical for you, consider disabling backups for the PARTITIONED cache. When backups are enabled, the Ignite cache engine maintains a remote copy of each entry, which requires network exchanges. To turn off the backup's copy, use the following cache configuration:

<bean class="org.apache.ignite.configuration.IgniteConfiguration">
    <property name="cacheConfiguration">
        <bean class="org.apache.ignite.configuration.CacheConfiguration">
            <!-- Set cache mode. -->
            <property name="cacheMode" value="PARTITIONED"/>
            <!-- Set number of backups to 0-->
            <property name="backups" value="0"/>
        </bean>
    </property>
</bean>

7. Synchronizing the requests for the same key. Let's explain with an example. Assume, your application has to handle 5000 requests per second. Most of them requested by one key. All the threads follow the following logic: If there is no value for the key in the cache, I query to the database. In the end, each of the threads goes to the database and updates the value for the key into the cache. As a result, the application spends more time than if the cache was not there at all. This is one of the common reasons your application slows down whenever you are using cache.

However, the solution to this problem is simple: synchronizing the requests for the same keys. Since version 2.1, Apache Ignite has supported the @Cacheable annotation with sync attributes which ensure that a single thread is forming the cache value. To achieve this, you have to add the sync attribute as follows:

@Cacheable(value = "exchangerate", sync = true)
public String getExchangerate(String region) {
}

8. Turn off or tune durable memory. Since version 2.1, Apache Ignite has had its own persistence implementation. Unfortunately, persistence slows down the system. The WAL slows down the system even more. If you do not need the data durability, you can disable or turn off the WAL archiving. In Apache Ignite, starting from version 2.4, it is possible to disable WAL without restarting the entire cluster as shown below:

ALTER TABLE tableName NOLOGGING
ALTER TABLE tableName LOGGING

By the way, you can also tune the WAL logging level according to your requirements. By default, the WAL log level is enabled on DEFAULT mode, which guaranties the highest level of data durability. You can change the log to one of the following levels:

1. LOG_ONLY.
2. BACKGROUND.
3. NONE.

Caching gives enormous performance benefits, saves unnecessary network roundtrips, and reduces CPU costs. Many believe that caching is such an easy way to make everything faster and cooler. However, as practice shows, the incorrect use of caching only makes thing worse. Caching is the mechanism that only gives performance boosts when you use it correctly. So, remember this before implementing it in your project, take measurements before and after on all related cases.

Don't hesitate to leave your comments or ideas if you have any. Portions of this article were taken from The Apache Ignite Book. If it got you interested, check out the rest of the book for more helpful information.

Cache (computing) Apache Ignite Web application Database Data (computing) cluster garbage collection Java (programming language) dev

Published at DZone with permission of Shamim Bhuiyan. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Scalable Data Grid Using Apache Ignite
  • Providing Enum Consistency Between Application and Data
  • What Developers Need to Know About Table Geo-Partitioning
  • Implement a Distributed Database to Your Java Application

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!