-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scala implementation with Futures #4
Comments
Where is the concurrency here? |
Only the leaf nodes in the Future tree complete immediately with the value, as they should. If you run the program, it will fully use all available cores to perform the calculations. |
Do I'm don't think just looking at the CPU usage is the right way to determine concurrency/parallelism as it may arise from JVM's activities like GC, rather than from the program itself. |
Actor's are no coroutines. |
Call to the Future |
Future in Scala are similar to Async to .NET. Since your .NET code uses async feature, correct way to compare would be against Future implementation |
@naveensky I don't think they're the same at all, due to how awaiting works. |
is the counterpart to
while
is the counterpart to
languages work different and have different names for stuff (specially .NET) |
@tuxychandru - await keyword is more or less same as Await in scala. Both wait for Task(.NET) or Future(scala) to complete before moving ahead. If they are not used, in .NET the return type of calling method is Task while in Scala it is Future[T]. If you use them, in .NET you get a result of enclosing type. |
@naveensky Their return type is identical, but their behavior is very different. See @Daxten's reply. |
@Daxten Why isn't creating actors the same as creating threads in same execution context? Also if I understand correctly isn't the way Futures are used here the same as submitting tasks to an |
An actor is a container for State, Behavior, a Mailbox, Children and a Supervisor Strategy. All of this is encapsulated behind an Actor Reference. Finally, this happens When an Actor Terminates. which is different to what a Thread is. |
yes |
Is there anyway to introduce a sleep in the leaf Futures, without blocking the underlying thread? That can demonstrate concurrency in the program, if it terminates in few seconds. For example, I can throw in a |
With |
To "sleep" inside an async function, you should use a scheduler, for example |
outputs: See you? |
@tuxychandru There is fully sequential version
and it works in ~50ms: sbt (root)> runMain SkynetSync
|
@tuxychandru Try also this:
it shows, of course: |
@tuxychandru There is Futures without successfuls
Results: [info] Running skynet.SkynetAsync
Still as from 2x to 3x faster than Go. |
@tuxychandru Even with Future.sucessful it still works async:
shows: See you? |
@tuxychandru You are right that this doesn't work async
and shows only one "Is it?" But this still works async
and shows a lot of "See you?" before dies. So with successfuls it is optimized to do not spawn unnecessary asyncs. |
Here's the benchmark implemented using Scala
Future
Runs in 250ms on my i7 laptop. For comparison the Akka version takes about 8200ms and Go takes about 750ms.
The text was updated successfully, but these errors were encountered: