<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Feb 19, 2014 at 1:03 PM, Sanne Grinovero <span dir="ltr">&lt;<a href="mailto:sanne@infinispan.org" target="_blank">sanne@infinispan.org</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On 19 February 2014 07:12, Galder Zamarreņo &lt;<a href="mailto:galder@redhat.com">galder@redhat.com</a>&gt; wrote:<br>


&gt;<br>
&gt; On 03 Feb 2014, at 19:01, Dan Berindei &lt;<a href="mailto:dan.berindei@gmail.com">dan.berindei@gmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; On Mon, Feb 3, 2014 at 6:28 PM, Radim Vansa &lt;<a href="mailto:rvansa@redhat.com">rvansa@redhat.com</a>&gt; wrote:<br>
&gt;&gt; &gt;&gt;&gt;&gt; For sync we would want to invoke directly to avoid context switching.<br>
&gt;&gt; &gt;&gt;&gt; I think you haven&#39;t properly understood what I was talking about: the<br>
&gt;&gt; &gt;&gt;&gt; putAsync should not switch context at all in the ideal design. It should<br>
&gt;&gt; &gt;&gt;&gt; traverse through the interceptors all the way down (logically, in<br>
&gt;&gt; &gt;&gt;&gt; current behaviour), invoke JGroups async API and jump out. Then, as soon<br>
&gt;&gt; &gt;&gt;&gt; as the response is received, the thread which delivered it should<br>
&gt;&gt; &gt;&gt;&gt; traverse the interceptor stack up (again, logically), and fire the future.<br>
&gt;&gt; &gt; A Future doesn&#39;t make much sense with an async transport. &nbsp;The problem<br>
&gt;&gt; &gt; is with an async transport you never get back a response so you never<br>
&gt;&gt; &gt; know when the actual command is completed and thus a Future is<br>
&gt;&gt; &gt; worthless. &nbsp;The caller wouldn&#39;t know if they could rely on the use of<br>
&gt;&gt; &gt; the Future or not.<br>
&gt;&gt;<br>
&gt;&gt; You&#39;re right, there&#39;s one important difference between putAsync and put<br>
&gt;&gt; with async transport: in the first case you can find out when the<br>
&gt;&gt; request is completed while you cannot with the latter. Not requiring the<br>
&gt;&gt; ack can be an important optimization. I think that both versions are<br>
&gt;&gt; very valid: first mostly for bulk operations = reduction of latency,<br>
&gt;&gt; second for modifications that are acceptable to fail without handling that.<br>
&gt;&gt; I had the first case in my mind when talking about async operations, and<br>
&gt;&gt; there the futures are necessary.<br>
&gt;&gt;<br>
&gt;&gt; A couple more differences:<br>
&gt;&gt; 1. You can&#39;t do commitAsync(), but you can configure the commit to be replicated asynchronously (1PC). Although we did talk about removing that option...<br>
&gt;&gt; 2. If you do putAsync(k, v1); putAsync(k, v2), there is no ordering between the two and you might end up with k=v1 in the cache.<br>
&gt;<br>
&gt; If there&rsquo;s any relationship between both puts for the caller thread, the caller must make sure that the second put is only called after the first has completed.<br>
<br>
</div></div>Actually in such a case I would strongly expect Infinispan to keep the<br>
two operations in order. This is not to be pushed on user&#39;s<br>
responsibility.<br></blockquote><div><br></div><div>I think you&#39;re talking about some other kind of putAsync(k, v) than we have now... all the work in putAsync happens on a separate thread, so there is no ordering between two separate putAsync calls whatsoever.<br>

<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class=""><br>
&gt;<br>
&gt; If there&rsquo;s separate threads calling it and it relies on this, it should call replace the second time, i.e. replaceAsync(k, v1, v2) to get the guarantees it wants.<br>
&gt;<br>
&gt; What is really important is that the order in which they are executed in one node/replica is the same order in which they&rsquo;re executed in all other nodes. This was something that was not maintained when async marshalling was enabled.<br>


<br>
</div>+1000<br>
<br>
But also I&#39;d stress that any sync operation should have a Future<br>
returned, someone in this long thread suggested to have an option to<br>
drop it for example to speedup bulk imports, but I really can&#39;t see a<br>
scenario in which I wouldn&#39;t want to know about a failure. Let&#39;s not<br>
do the same mistake that made MongoDB so &quot;popular&quot; ;-)<br>
Bulk imports can still be mad efficient without strictly needing to go<br>
these lenghts.<br></blockquote><div><br></div><div>You mean if the operation is synchronous, but the cache store/replication is async? I don&#39;t see how sync operations could return a Future, since most of them already have a return value. <br>

<br>Bulk imports could certainly use putAsync(k, v), and that would indeed return a Future.<br><br></div><div>&nbsp;</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span class="HOEnZb"><font color="#888888"><br>
Sanne<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Also it depends what you are trying to do with async. &nbsp;Currently async<br>
&gt;&gt; &gt; transport is only for sending messages to another node, we never think<br>
&gt;&gt; &gt; of when we are the owning node. &nbsp;In this case the calling thread would<br>
&gt;&gt; &gt; have to go down the interceptor stack and acquire any locks if it is<br>
&gt;&gt; &gt; the owner, thus causing this &quot;async&quot; to block if you have any<br>
&gt;&gt; &gt; contention on the given key. &nbsp;The use of another thread would allow<br>
&gt;&gt; &gt; the calling thread to be able to return immediately no matter what<br>
&gt;&gt; &gt; else is occurring. &nbsp;Also I don&#39;t see what is so wrong about having a<br>
&gt;&gt; &gt; context switch to run something asynchronously, we shouldn&#39;t have a<br>
&gt;&gt; &gt; context switch to block the user thread imo, which is very possible<br>
&gt;&gt; &gt; with locking.<br>
&gt;&gt;<br>
&gt;&gt; This is an important notice! Locking would complicate the design a lot,<br>
&gt;&gt; because the thread in &quot;async&quot; mode should do only tryLocks - if this<br>
&gt;&gt; fails, further processing should be dispatched to another thread. Not<br>
&gt;&gt; sure if this could be implemented at all, because the thread may be<br>
&gt;&gt; blocked inside JGroups as well (async API is about receiving the<br>
&gt;&gt; response asynchronously, not about sending the message asynchronously).<br>
&gt;&gt;<br>
&gt;&gt; I don&#39;t say that the context switch is that bad. My concern is that you<br>
&gt;&gt; have a very limited amount of requests that can be processed in<br>
&gt;&gt; parallel. I consider a &quot;request&quot; something pretty lightweight in concept<br>
&gt;&gt; - but one thread per request makes this rather heavyweight stuff.<br>
&gt;&gt;<br>
&gt;&gt; We did talk in Farnborough/Palma about removing the current LockManager with a queue-based structure like the one used for ordering total-order transactions. And about removing the implicit stack in the current interceptor stack with an explicit stack, to allow resuming a command mid-execution. But the feeling I got was that neither is going to make it into 7.0.<br>


&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; +1 much cleaner, I love it. Actually wasn&#39;t aware the current code<br>
&gt;&gt; &gt;&gt; didn&#39;t do this :-(<br>
&gt;&gt; &gt; This is what the current async transport does, but it does nothing with Futures.<br>
&gt;&gt;<br>
&gt;&gt; Nevermind the futures, this is not the important part. It&#39;s not about<br>
&gt;&gt; async transport neither, it&#39;s about async executors.<br>
&gt;&gt; (okay, the thread was about dropping async transport, I have hijacked it)<br>
&gt;&gt;<br>
&gt;&gt; Radim<br>
&gt;&gt;<br>
&gt;&gt; --<br>
&gt;&gt; Radim Vansa &lt;<a href="mailto:rvansa@redhat.com">rvansa@redhat.com</a>&gt;<br>
&gt;&gt; JBoss DataGrid QA<br>
&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; infinispan-dev mailing list<br>
&gt;&gt; <a href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.jboss.org</a><br>
&gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/infinispan-dev</a><br>
&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; infinispan-dev mailing list<br>
&gt;&gt; <a href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.jboss.org</a><br>
&gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/infinispan-dev</a><br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; Galder Zamarreņo<br>
&gt; <a href="mailto:galder@redhat.com">galder@redhat.com</a><br>
&gt; <a href="http://twitter.com/galderz" target="_blank">twitter.com/galderz</a><br>
&gt;<br>
&gt; Project Lead, Escalante<br>
&gt; <a href="http://escalante.io" target="_blank">http://escalante.io</a><br>
&gt;<br>
&gt; Engineer, Infinispan<br>
&gt; <a href="http://infinispan.org" target="_blank">http://infinispan.org</a><br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; infinispan-dev mailing list<br>
&gt; <a href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/infinispan-dev</a><br>
<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></div></div></blockquote></div><br></div></div>