このコンテンツは選択した言語では利用できません。

Chapter 7. Hints for program developers


There are also several hints for developers which can be easily applied to the client application and will boost up the performance.

7.1. Ignore return values

When you’re not interested in returning value of the #put(k, v) or #remove(k) method, use Flag.IGNORE_RETURN_VALUES flag as shown below:

Using Flag.IGNORE_RETURN_VALUES

Cache noPreviousValueCache = cache.getAdvancedCache().withFlags(Flag.IGNORE_RETURN_VALUES);
noPreviousValueCache.put(k, v);
Copy to Clipboard Toggle word wrap

It is also possible to set this flag using ConfigurationBuilder

Using ConfigurationBuilder settings

ConfigurationBuilder cb = new ConfigurationBuilder();
cb.unsafe().unreliableReturnValues(true);
Copy to Clipboard Toggle word wrap

7.2. Use Externalizer for marshalling

Red Hat Data Grid uses JBoss Marshalling to transfer objects over the wire. The most efficient way to marshall user data is to provide an AdvancedExternalizer. This solutions prevents JBoss Marshalling from sending class name over the network and allows to save some bandwidth:

User entity with Externalizer

import org.infinispan.marshall.AdvancedExternalizer;

public class Book {

   final String name;
   final String author;

   public Book(String name, String author) {
      this.name = name;
      this.author = author;
   }

   public static class BookExternalizer
            implements AdvancedExternalizer<Book> {

      @Override
      public void writeObject(ObjectOutput output, Book book)
            throws IOException {
         output.writeObject(book.name);
         output.writeObject(book.author);
      }

      @Override
      public Person readObject(ObjectInput input)
            throws IOException, ClassNotFoundException {
         return new Person((String) input.readObject(), (String) input.readObject());
      }

      @Override
      public Set<Class<? extends Book>> getTypeClasses() {
         return Util.<Class<? extends Book>>asSet(Book.class);
      }

      @Override
      public Integer getId() {
         return 2345;
      }
   }
}
Copy to Clipboard Toggle word wrap

The Externalizer must be registered in cache configuration. See configuration examples below:

Adding Externalizer using XML

<cache-container>
   <serialization>
      <advanced-externalizer class="Book$BookExternalizer"/>
   </serialization>
</cache-container>
Copy to Clipboard Toggle word wrap

Adding Externalizer using Java

GlobalConfigurationBuilder builder = ...
builder.serialization().addAdvancedExternalizer(new Book.BookExternalizer());
Copy to Clipboard Toggle word wrap

7.3. Storing Strings efficiently

If your strings are mostly ASCII, convert them to UTF-8 and store them as byte[]:

  • Using String#getBytes("UTF-8") allows to decrease size of the object
  • Consider using G1 GC with additional JVM flag -XX:+UseStringDeduplication. This allows to decrease memory footprint (see JEP 192 for details).

7.4. Use simple cache for local caches

When you don’t need the full feature set of caches, you can set local cache to "simple" mode and achieve non-trivial speedup while still using Red Hat Data Grid API.

This is an example comparison of the difference, randomly reading/writing into cache with 2048 entries as executed on 2x8-core Intel® Xeon® CPU E5-2640 v3 @ 2.60GHz:

Expand
Table 7.1. Number of operations per second (± std. dev.)
Cache typesingle-threaded cache.get(…​)single-threaded cache.put(…​)32 threads cache.get(…​)32 threads cache.put(…​)

Local cache

14,321,510 ± 260,807

1,141,168 ± 6,079

236,644,227 ± 2,657,918

2,287,708 ± 100,236

Simple cache

38,144,468 ± 575,420

11,706,053 ± 92,515

836,510,727 ± 3,176,794

47,971,836 ± 1,125,298

CHM

60,592,770 ± 924,368

23,533,141 ± 98,632

1,369,521,754 ± 4,919,753

75,839,121 ± 3,319,835

The CHM shows comparison for ConcurrentHashMap from JSR-166 with pluggable equality/hashCode function, which is used as the underlying storage in Red Hat Data Grid.

Even though we use JMH to prevent some common pitfals of microbenchmarking, consider these results only aproximative. Your mileage may vary.

トップに戻る
Red Hat logoGithubredditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。 最新の更新を見る.

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

Theme

© 2025 Red Hat