<div dir="ltr">Have you tried regular optimistic/pessimistic transactions as well? They *should* have less issues with the OOB thread pool than non-tx mode, and I&#39;m quite curious how they stack against TO in such a large cluster.</div>

<div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jul 29, 2014 at 5:38 PM, Bela Ban <span dir="ltr">&lt;<a href="mailto:bban@redhat.com" target="_blank">bban@redhat.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Following up on my own email, I changed the config to use Pedro&#39;s<br>
excellent total order implementation:<br>
<br>
&lt;transaction transactionMode=&quot;TRANSACTIONAL&quot;<br>
transactionProtocol=&quot;TOTAL_ORDER&quot; lockingMode=&quot;OPTIMISTIC&quot;<br>
useEagerLocking=&quot;true&quot; eagerLockSingleNode=&quot;true&quot;&gt;<br>
             &lt;recovery enabled=&quot;false&quot;/&gt;<br>
<br>
With 100 nodes and 25 requester threads/node, I did NOT run into any<br>
locking issues !<br>
<br>
I could even go up to 200 requester threads/node and the perf was ~<br>
7&#39;000-8&#39;000 requests/sec/node. Not too bad !<br>
<br>
This really validates the concept of lockless total-order dissemination<br>
of TXs; for the first time, this has been tested on a large(r) scale<br>
(previously only on 25 nodes) and IT WORKS ! :-)<br>
<br>
I still believe we should implement my suggested solution for non-TO<br>
configs, but short of configuring thread pools of 1000 threads or<br>
higher, I hope TO will allow me to finally test a 500 node Infinispan<br>
cluster !<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
On 29/07/14 15:56, Bela Ban wrote:<br>
&gt; Hi guys,<br>
&gt;<br>
&gt; sorry for the long post, but I do think I ran into an important problem<br>
&gt; and we need to fix it ... :-)<br>
&gt;<br>
&gt; I&#39;ve spent the last couple of days running the IspnPerfTest [1] perftest<br>
&gt; on Google Compute Engine (GCE), and I&#39;ve run into a problem with<br>
&gt; Infinispan. It is a design problem and can be mitigated by sizing thread<br>
&gt; pools correctly, but cannot be eliminated entirely.<br>
&gt;<br>
&gt;<br>
&gt; Symptom:<br>
&gt; --------<br>
&gt; IspnPerfTest has every node in a cluster perform 20&#39;000 requests on keys<br>
&gt; in range [1..20000].<br>
&gt;<br>
&gt; 80% of the requests are reads and 20% writes.<br>
&gt;<br>
&gt; By default, we have 25 requester threads per node and 100 nodes in a<br>
&gt; cluster, so a total of 2500 requester threads.<br>
&gt;<br>
&gt; The cache used is NON-TRANSACTIONAL / dist-sync / 2 owners:<br>
&gt;<br>
&gt; &lt;namedCache name=&quot;clusteredCache&quot;&gt;<br>
&gt;        &lt;clustering mode=&quot;distribution&quot;&gt;<br>
&gt;            &lt;stateTransfer awaitInitialTransfer=&quot;true&quot;/&gt;<br>
&gt;            &lt;hash numOwners=&quot;2&quot;/&gt;<br>
&gt;            &lt;sync replTimeout=&quot;20000&quot;/&gt;<br>
&gt;        &lt;/clustering&gt;<br>
&gt;<br>
&gt;        &lt;transaction transactionMode=&quot;NON_TRANSACTIONAL&quot;<br>
&gt; useEagerLocking=&quot;true&quot;<br>
&gt;             eagerLockSingleNode=&quot;true&quot;  /&gt;<br>
&gt;        &lt;locking lockAcquisitionTimeout=&quot;5000&quot; concurrencyLevel=&quot;1000&quot;<br>
&gt;                 isolationLevel=&quot;READ_COMMITTED&quot; useLockStriping=&quot;false&quot; /&gt;<br>
&gt; &lt;/namedCache&gt;<br>
&gt;<br>
&gt; It has 2 owners, a lock acquisition timeout of 5s and a repl timeout of<br>
&gt; 20s. Lock stripting is off, so we have 1 lock per key.<br>
&gt;<br>
&gt; When I run the test, I always get errors like those below:<br>
&gt;<br>
&gt; org.infinispan.util.concurrent.TimeoutException: Unable to acquire lock<br>
&gt; after [10 seconds] on key [19386] for requestor [Thread[invoker-3,5,main]]!<br>
&gt; Lock held by [Thread[OOB-194,ispn-perf-test,m5.1,5,main]]<br>
&gt;<br>
&gt; and<br>
&gt;<br>
&gt; org.infinispan.util.concurrent.TimeoutException: Node m8.1 timed out<br>
&gt;<br>
&gt;<br>
&gt; Investigation:<br>
&gt; ------------<br>
&gt; When I looked at UNICAST3, I saw a lot of missing messages on the<br>
&gt; receive side and unacked messages on the send side. This caused me to<br>
&gt; look into the (mainly OOB) thread pools and - voila - maxed out !<br>
&gt;<br>
&gt; I learned from Pedro that the Infinispan internal thread pool (with a<br>
&gt; default of 32 threads) can be configured, so I increased it to 300 and<br>
&gt; increased the OOB pools as well.<br>
&gt;<br>
&gt; This mitigated the problem somewhat, but when I increased the requester<br>
&gt; threads to 100, I had the same problem again. Apparently, the Infinispan<br>
&gt; internal thread pool uses a rejection policy of &quot;run&quot; and thus uses the<br>
&gt; JGroups (OOB) thread when exhausted.<br>
&gt;<br>
&gt; I learned (from Pedro and Mircea) that GETs and PUTs work as follows in<br>
&gt; dist-sync / 2 owners:<br>
&gt; - GETs are sent to the primary and backup owners and the first response<br>
&gt; received is returned to the caller. No locks are acquired, so GETs<br>
&gt; shouldn&#39;t cause problems.<br>
&gt;<br>
&gt; - A PUT(K) is sent to the primary owner of K<br>
&gt; - The primary owner<br>
&gt;        (1) locks K<br>
&gt;        (2) updates the backup owner synchronously *while holding the lock*<br>
&gt;        (3) releases the lock<br>
&gt;<br>
&gt;<br>
&gt; Hypothesis<br>
&gt; ----------<br>
&gt; (2) above is done while holding the lock. The sync update of the backup<br>
&gt; owner is done with the lock held to guarantee that the primary and<br>
&gt; backup owner of K have the same values for K.<br>
&gt;<br>
&gt; However, the sync update *inside the lock scope* slows things down (can<br>
&gt; it also lead to deadlocks?); there&#39;s the risk that the request is<br>
&gt; dropped due to a full incoming thread pool, or that the response is not<br>
&gt; received because of the same, or that the locking at the backup owner<br>
&gt; blocks for some time.<br>
&gt;<br>
&gt; If we have many threads modifying the same key, then we have a backlog<br>
&gt; of locking work against that key. Say we have 100 requester threads and<br>
&gt; a 100 node cluster. This means that we have 10&#39;000 threads accessing<br>
&gt; keys; with 2&#39;000 writers there&#39;s a big chance that some writers pick the<br>
&gt; same key at the same time.<br>
&gt;<br>
&gt; For example, if we have 100 threads accessing key K and it takes 3ms to<br>
&gt; replicate K to the backup owner, then the last of the 100 threads waits<br>
&gt; ~300ms before it gets a chance to lock K on the primary owner and<br>
&gt; replicate it as well.<br>
&gt;<br>
&gt; Just a small hiccup in sending the PUT to the primary owner, sending the<br>
&gt; modification to the backup owner, waitting for the response, or GC, and<br>
&gt; the delay will quickly become bigger.<br>
&gt;<br>
&gt;<br>
&gt; Verification<br>
&gt; ----------<br>
&gt; To verify the above, I set numOwners to 1. This means that the primary<br>
&gt; owner of K does *not* send the modification to the backup owner, it only<br>
&gt; locks K, modifies K and unlocks K again.<br>
&gt;<br>
&gt; I ran the IspnPerfTest again on 100 nodes, with 25 requesters, and NO<br>
&gt; PROBLEM !<br>
&gt;<br>
&gt; I then increased the requesters to 100, 150 and 200 and the test<br>
&gt; completed flawlessly ! Performance was around *40&#39;000 requests per node<br>
&gt; per sec* on 4-core boxes !<br>
&gt;<br>
&gt;<br>
&gt; Root cause<br>
&gt; ---------<br>
&gt; *******************<br>
&gt; The root cause is the sync RPC of K to the backup owner(s) of K while<br>
&gt; the primary owner holds the lock for K.<br>
&gt; *******************<br>
&gt;<br>
&gt; This causes a backlog of threads waiting for the lock and that backlog<br>
&gt; can grow to exhaust the thread pools. First the Infinispan internal<br>
&gt; thread pool, then the JGroups OOB thread pool. The latter causes<br>
&gt; retransmissions to get dropped, which compounds the problem...<br>
&gt;<br>
&gt;<br>
&gt; Goal<br>
&gt; ----<br>
&gt; The goal is to make sure that primary and backup owner(s) of K have the<br>
&gt; same value for K.<br>
&gt;<br>
&gt; Simply sending the modification to the backup owner(s) asynchronously<br>
&gt; won&#39;t guarantee this, as modification messages might get processed out<br>
&gt; of order as they&#39;re OOB !<br>
&gt;<br>
&gt;<br>
&gt; Suggested solution<br>
&gt; ----------------<br>
&gt; The modification RPC needs to be invoked *outside of the lock scope*:<br>
&gt; - lock K<br>
&gt; - modify K<br>
&gt; - unlock K<br>
&gt; - send modification to backup owner(s) // outside the lock scope<br>
&gt;<br>
&gt; The primary owner puts the modification of K into a queue from where a<br>
&gt; separate thread/task removes it. The thread then invokes the PUT(K) on<br>
&gt; the backup owner(s).<br>
&gt;<br>
&gt; The queue has the modified keys in FIFO order, so the modifications<br>
&gt; arrive at the backup owner(s) in the right order.<br>
&gt;<br>
&gt; This requires that the way GET is implemented changes slightly: instead<br>
&gt; of invoking a GET on all owners of K, we only invoke it on the primary<br>
&gt; owner, then the next-in-line etc.<br>
&gt;<br>
&gt; The reason for this is that the backup owner(s) may not yet have<br>
&gt; received the modification of K.<br>
&gt;<br>
&gt; This is a better impl anyway (we discussed this before) becuse it<br>
&gt; generates less traffic; in the normal case, all but 1 GET requests are<br>
&gt; unnecessary.<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; Improvement<br>
&gt; -----------<br>
&gt; The above solution can be simplified and even made more efficient.<br>
&gt; Re-using concepts from IRAC [2], we can simply store the modified *keys*<br>
&gt; in the modification queue. The modification replication thread removes<br>
&gt; the key, gets the current value and invokes a PUT/REMOVE on the backup<br>
&gt; owner(s).<br>
&gt;<br>
&gt; Even better: a key is only ever added *once*, so if we have [5,2,17,3],<br>
&gt; adding key 2 is a no-op because the processing of key 2 (in second<br>
&gt; position in the queue) will fetch the up-to-date value anyway !<br>
&gt;<br>
&gt;<br>
&gt; Misc<br>
&gt; ----<br>
&gt; - Could we possibly use total order to send the updates in TO ? TBD (Pedro?)<br>
&gt;<br>
&gt;<br>
&gt; Thoughts ?<br>
&gt;<br>
&gt;<br>
&gt; [1] <a href="https://github.com/belaban/IspnPerfTest" target="_blank">https://github.com/belaban/IspnPerfTest</a><br>
&gt; [2]<br>
&gt; <a href="https://github.com/infinispan/infinispan/wiki/RAC:-Reliable-Asynchronous-Clustering" target="_blank">https://github.com/infinispan/infinispan/wiki/RAC:-Reliable-Asynchronous-Clustering</a><br>
&gt;<br>
<br>
--<br>
Bela Ban, JGroups lead (<a href="http://www.jgroups.org" target="_blank">http://www.jgroups.org</a>)<br>
_______________________________________________<br>
infinispan-dev mailing list<br>
<a href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/infinispan-dev</a><br>
</div></div></blockquote></div><br></div>