<p>I am facing performance issues with hazelcast configured as client-server.
I have one K8S Cluster consisting of 5 Nodes and 1 Master Node. Each node is of 64 GB of RAM and 16 Core (Hazelcast Version 3.12.4)
Hazelcast server is deployed on K8S with one POD on one of the nodes available in cluster
My Client is deployed on K8S which is connected to above Hazelcast with smart client (Hazelcast discovery enabled for K8S). There are a total 10 PODs of my applications with each node consisting of 2 PODs of my application.</p>

<p>I am running different different APIs and performing load testing of my application (Approx 110 Threads at a time shared across all 10 PODs)</p>

<p>I am having the following piece of code in my application to get cache.</p>

<pre><code>public Map&lt;Object, Object&gt; get(String cacheId, Long lTenantId) {
     String strMethodName="get";
     long t1 = System.currentTimeMillis();
     Map&lt;Object,Object&gt; cacheDataMap=hazelcastInstance.getMap(cacheId);
     long totalTimeTaken = (System.currentTimeMillis()-t1);
     if(totalTimeTaken &gt; 10){
         logger.warnLog(CLASSNAME, strMethodName,"Total time taken by "+cacheId+" identifier for get operation is : "+totalTimeTaken+" ms");
      }
      return cacheDataMap;
}
</code></pre>

<p>The way my application uses this map varies like</p>

<p>1) </p>

<pre><code>map.get(key);
</code></pre>

<p>2) </p>

<pre><code>Set keys = map.keySet();
   Iterator iterator = keys.iterator(); //I changed to keyset iterator because entryset was causing lot of performance issues
   while (iterator.hasNext()) {
      // doing stuff
   }
</code></pre>

<p>When all My APIs are started for Load I am getting these logs printed in an application (Total time taken by....) where each cache access time is > 10 miliseconds and this is causing performance issues and hence I am not able to achieve my desired TPS for all APIs.</p>

<p>There are approx 300 Maps are stored in cache where total size of the cache is 4.22 MB</p>

<p>I am using near cache configuration and also on the management center it is showing effectiveness as 100%. (This was taken when hazelcast.client.statistics.enabled was enabled).</p>

<p>I have also tried with 8 PODs deployed on 4 Nodes and 1 dedicated node for Hazelcast server but the issue remains the same. There are no issues observed when I am connecting Hazelcast as embedded and I am able to achieve my desired TPS for all APIs.</p>

<p>Am I Missing any configuration or any other thing which is causing this problem?</p>

<p>Here is my hazelcast-client.xml</p>

<pre><code>&lt;hazelcast-client
xmlns="http://www.hazelcast.com/schema/client-config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.hazelcast.com/schema/client-config
                  http://hazelcast.com/schema/client-config/hazelcast-client-config-3.11.xsd"&gt;

&lt;group&gt;
&lt;name&gt;dev&lt;/name&gt;
&lt;/group&gt;
&lt;instance-name&gt;hazelcast&lt;/instance-name&gt;
&lt;properties&gt;
&lt;property name="hazelcast.client.shuffle.member.list"&gt;true&lt;/property&gt;
&lt;property name="hazelcast.client.heartbeat.timeout"&gt;600000&lt;/property&gt;
&lt;property name="hazelcast.client.heartbeat.interval"&gt;180000&lt;/property&gt;
&lt;property name="hazelcast.client.event.queue.capacity"&gt;1000000&lt;/property&gt;
&lt;property name="hazelcast.client.invocation.timeout.seconds"&gt;120&lt;/property&gt;
&lt;property name="hazelcast.client.statistics.enabled"&gt;false&lt;/property&gt;
&lt;property name="hazelcast.discovery.enabled"&gt;true&lt;/property&gt;
&lt;property name="hazelcast.map.invalidation.batch.enabled"&gt;false&lt;/property&gt;
&lt;/properties&gt;

&lt;network&gt;
&lt;discovery-strategies&gt;
&lt;discovery-strategy enabled="true"
class="com.hazelcast.kubernetes.HazelcastKubernetesDiscoveryStrategy"&gt;
&lt;properties&gt;
&lt;property name="service-name"&gt;&lt;service-name&gt;&lt;/property&gt;
&lt;property name="namespace"&gt;&lt;namespace&gt;&lt;/property&gt;
&lt;/properties&gt;
&lt;/discovery-strategy&gt;
&lt;/discovery-strategies&gt;
&lt;smart-routing&gt;true&lt;/smart-routing&gt;
&lt;redo-operation&gt;true&lt;/redo-operation&gt;
&lt;connection-timeout&gt;90000&lt;/connection-timeout&gt;
&lt;connection-attempt-period&gt;100&lt;/connection-attempt-period&gt;
&lt;connection-attempt-limit&gt;0&lt;/connection-attempt-limit&gt;

&lt;/network&gt;

&lt;near-cache name="default"&gt;
                &lt;in-memory-format&gt;OBJECT&lt;/in-memory-format&gt;
                &lt;serialize-keys&gt;true&lt;/serialize-keys&gt;
                &lt;invalidate-on-change&gt;true&lt;/invalidate-on-change&gt;
                &lt;eviction eviction-policy="NONE" max-size-policy="ENTRY_COUNT"/&gt;
        &lt;/near-cache&gt;
&lt;/hazelcast-client&gt;
</code></pre>

<p>Here is my hazelcast.xml</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;

&lt;hazelcast xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-3.11.xsd"
           xmlns="http://www.hazelcast.com/schema/config"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;

  &lt;management-center enabled="${hazelcast.mancenter.enabled}"&gt;${hazelcast.mancenter.url}&lt;/management-center&gt;

&lt;/hazelcast&gt;
</code></pre>

<p>The goal of a cache is to get the value from a key as fast as possible. In general, you already have the key, and request the value. That means you send a request to any node, this looks in the partition table which partition the key belongs to, and forwards the query to the relevant node.</p>

<p>In your second use-case, you try to get all keys from all nodes:</p>

<pre><code>Set keys = map.keySet();
Iterator iterator = keys.iterator();
while (iterator.hasNext()) {
    // doing stuff
}
</code></pre>

<p>To return fast as possible, Hazelcast will return a lazy implementation of the <code>Iterator</code>. For each call to <code>next()</code>, it will need first to retrieve the key following the above process. Plus, I assume the <code>// doing stuff</code> code actually loads the value from the key.</p>

<p>In conclusion, please avoid at all costs using <code>map.keySet()</code>. Unless I know more about your context and your use-case, I unfortunately cannot provide with a relevant alternative.</p>
