Return-Path: X-Original-To: apmail-ignite-dev-archive@minotaur.apache.org Delivered-To: apmail-ignite-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7A89D18B3F for ; Sat, 10 Oct 2015 09:40:11 +0000 (UTC) Received: (qmail 98920 invoked by uid 500); 10 Oct 2015 09:40:11 -0000 Delivered-To: apmail-ignite-dev-archive@ignite.apache.org Received: (qmail 98875 invoked by uid 500); 10 Oct 2015 09:40:11 -0000 Mailing-List: contact dev-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list dev@ignite.apache.org Received: (qmail 98863 invoked by uid 99); 10 Oct 2015 09:40:10 -0000 Received: from Unknown (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 10 Oct 2015 09:40:10 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 79386C0BDA for ; Sat, 10 Oct 2015 09:40:10 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.9 X-Spam-Level: ** X-Spam-Status: No, score=2.9 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=3, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=disabled Authentication-Results: spamd4-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id GNcyfUFphR5q for ; Sat, 10 Oct 2015 09:40:01 +0000 (UTC) Received: from mail-vk0-f47.google.com (mail-vk0-f47.google.com [209.85.213.47]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with ESMTPS id B62C2439B8 for ; Sat, 10 Oct 2015 09:40:00 +0000 (UTC) Received: by vkaw128 with SMTP id w128so8127899vka.0 for ; Sat, 10 Oct 2015 02:40:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=4wrtnjUvm30qlVNQmB0UdbusDKYRIPt0lq8yflYhxyY=; b=PYm8CL+EYDQGftTTAffqQGFFhmPpDha5Ylz7KYlJhO4zdXH1OkhZp1KTPW96ru4J9k cGY3BsNvbLlqQ3mlYFXDyrRSNU5HgZhdUKwXVWWWc+SxjRU5dBhrF5zhUBml4gq4g59j gHdPKeltpxd3TlUZnwifJ8ye/F1bIP1MQiB5lNC2PCrV/NVPHlvh83zM65s9rV/3f7CI Cy84pseK70BYch3wOtW8ZSuHEsxFCJ/tIVoMNb4go8i4y+fi6lnFdGYGLDoOpxVxE2bM 5LP4+X7Hb7j+AE5YEFfysS8SK9+LwDpfGcUM/aldhz70nxNNzapD2y7walWFZw+R8fe4 Z+2A== X-Received: by 10.31.8.131 with SMTP id 125mr11523206vki.45.1444470000142; Sat, 10 Oct 2015 02:40:00 -0700 (PDT) MIME-Version: 1.0 Received: by 10.103.48.132 with HTTP; Sat, 10 Oct 2015 02:39:20 -0700 (PDT) In-Reply-To: References: From: Sergi Vladykin Date: Sat, 10 Oct 2015 12:39:20 +0300 Message-ID: Subject: Re: .Net: separate methods for async operations. To: dev@ignite.apache.org Content-Type: multipart/alternative; boundary=001a11440fa23f4ecc0521bce1d7 --001a11440fa23f4ecc0521bce1d7 Content-Type: text/plain; charset=UTF-8 I think IgniteAsyncSupport is a big piece of crap even in java, sync/async API separation definitely must be done in another way. Sergi 2015-10-10 0:40 GMT+03:00 Dmitriy Setrakyan : > Pavel, can you explain how .NET async semantics are different from Java? > > On Fri, Oct 9, 2015 at 1:46 PM, Pavel Tupitsyn > wrote: > > > Hi Dmitry, > > > > > First of all, from my experience, the async APIs are used a lot less > > than sync > > ones > > > > This may be true, especially if the API is clunky. > > But .NET has async/await functionality which makes async code a lot > cleaner > > and easier. > > Good async/await support is very important, because it does not block > > current thread, which in turn is important for high load applications. > > All modern .NET APIs are async. > > > > > > > Secondly, the scope of this change would be huge. > > > > I don't think so. There are around 40 methods with async support in > current > > Ignite.NET. > > Adding their async counterparts will take a couple of hours at most. > > And it will simplify interop code somewhat because GetFuture goes away. > > > > > > > And lastly, I am against having .NET APIs different from Java APIs. > > > > Functionally they will be the same. But we should not try to bring Java > > semantics to .NET. > > Async methods in .NET are "T DoSomething()" + "Task > DoSomethingAsync()" > > and we should follow this pattern so our API looks familiar to .NET > > community. > > > > > > > // Line #2 > > > cache.Future().Get(); > > > > It is cache.GetFuture(). Pay attention to "X". This is very important: > > user has to specify correct return type according to return type of > > operation on "Line 1". > > Very annoying and error prone. There is even a style-checker warning > about > > such things. > > > > > > > 2 lines of code instead of one is not a big deal in my view. > > > > It is 2 times too much, sometimes even more. Imagine a situation where > you > > need to perform multiple async operations: > > > > cache.Get(1); > > var res = await cache.GetFuture().ToTask(); > > > > compute.Call(new MyCallable(res)) > > var res2 = await compute.GetFuture().ToTask() > > > > > > And with proper async API it can even be a one-liner. > > var res2 = await compute.CallAsync(new MyCallable(await > > cache.GetAsync(1))); > > > > > > API is the first thing a programmer sees in the new product. Let's do it > > right. > > > > Thanks, > > > > On Fri, Oct 9, 2015 at 7:17 PM, Dmitriy Setrakyan > > > wrote: > > > > > I don't think I like the proposed change. > > > > > > First of all, from my experience, the async APIs are used a lot less > than > > > sync ones, so having 2 lines of code for async calls is not a big deal > in > > > my view. > > > > > > Secondly, the scope of this change would be huge. We would have to > double > > > our Compute, Cache, Services, and many other APIs. Seems to me like a > > huge > > > amount of effort for a very questionable benefit, if any at all. One > can > > > argue, for example, that so many duplicate sync/async methods on all > the > > > APIs is more confusing, not less. > > > > > > And lastly, I am against having .NET APIs different from Java APIs. We > > > should have API parity as much as possible between all the platforms, > and > > > especially the .NET one, where we provide so many features. > > > > > > On Fri, Oct 9, 2015 at 7:05 AM, Pavel Tupitsyn > > > > wrote: > > > > > > > As a .Net dev, I support this change very much. > > > > > > > > Current design with 2 method calls is not easy to use, is error > prone, > > > and > > > > is not familiar to .Net crowd: > > > > > > > > var cache = ignite.GetCache().WithAsync(); > > > > var value = cache.Get(1); // Is it sync or async? Can't tell from > > code. > > > > > > In async mode this always returns 0. > > > > > > > > > > Yes, you are right. But then again, async documentation clearly says > that > > > you should get a future to get the actual asynchronous result. > > > > > > The proper code here is: > > > ----------- > > > var cache = ignite.GetCache().WithAsync(); > > > > > > // Line #1 > > > cache.Get(1); > > > > > > // Line #2 > > > cache.Future().Get(); > > > ----------- > > > > > > 2 lines of code instead of one is not a big deal in my view. > > > > > > > > > > var future = cache.GetFuture(); // User has to specify right > > > generic > > > > argument here. Not convenient, error prone, violates design > guidelines > > > > var actualValue = await future.ToTask(); > > > > > > > > > > > > As opposed to: > > > > var value = await cache.GetAsync(1).ToTask(); > > > > > > > > > > > > > > > > > Which is one line, obviously async, with proper generic inference. > > > > > > > > > > > > > > > > On Fri, Oct 9, 2015 at 4:47 PM, Vladimir Ozerov < > vozerov@gridgain.com> > > > > wrote: > > > > > > > > > Igniters, > > > > > > > > > > Some time ago we decided to merge sync and async methods. E.g. > > instead > > > of > > > > > ... > > > > > > > > > > interface Cache { > > > > > V get(K key); > > > > > Future getAsync(K key); > > > > > } > > > > > > > > > > ... we now have: > > > > > > > > > > interface Cache extends AsyncSupport { > > > > > V get(K key); > > > > > Cache withAsync(); > > > > > > > > > > Future lastFuture(); // From AsyncSupport, returns future for > the > > > > last > > > > > operation. > > > > > } > > > > > > > > > > This approach is questionable. Less methods is good, and all > methods > > go > > > > > through JCache API. But async mode became more complex and less > > usable. > > > > > This is especially obvious in Java 8 with its lambdas and > > > > > CompletableFuture. > > > > > > > > > > In .Net we blindly applied this approach as well. But in this world > > > > > AsyncSupport gives even less advantages than in Java: > > > > > 1) There is no JCache spec here; > > > > > 2) Core .Net API very often use paired sync and async operations in > > the > > > > > same class near each other - DoMethod(), DoMethodAsync() - and this > > is > > > > what > > > > > users normally expect from async-enabled classes. > > > > > 3) [AsyncSupported] attribute is not highlighted in Visual Studio. > > The > > > > only > > > > > way to understand that method supports async mode is to install > > > ReSharper > > > > > or to look into source code. > > > > > 4) .Net has native continuations support with async/await keywords. > > Our > > > > API > > > > > doesn't support it well. > > > > > > > > > > Having said that I want to return paired "async" operations to .Net > > > API: > > > > > interface ICache { > > > > > V Get(K key); > > > > > IFuture GetAsync(K key); > > > > > } > > > > > > > > > > It will add 25 new methods to ICache interface and remove 2. But > API > > > will > > > > > become much more friendly and natural for .Net users. > > > > > > > > > > Any thoughts/objections? > > > > > > > > > > Vladimir. > > > > > > > > > > > > > > > > > > > > > -- > > > > -- > > > > Pavel Tupitsyn > > > > GridGain Systems, Inc. > > > > www.gridgain.com > > > > > > > > > > > > > > > -- > > -- > > Pavel Tupitsyn > > GridGain Systems, Inc. > > www.gridgain.com > > > --001a11440fa23f4ecc0521bce1d7--