Discussion:
[dart-misc] Dart Threading Model
Jan Mostert
2015-12-15 08:22:49 UTC
Permalink
Hi, I'm busy investigating whether I can use Dart for a backend service on
a new project, but need to understand the threading model to know if it'll
work for me or not.

In Java I can do Runtime.getRuntime().availableProcessors() and then start
threads in proportion to the number of processors available to utilize all
CPUs / Cores on each machine which should give me great throughput on
IO-bounded operations.

What is the Dart Threading model? Does it follow a similar model to Java or
a model similar to NodeJS that has a single thread and an event loop?
--
For other discussions, see https://groups.google.com/a/dartlang.org/

For HOWTO questions, visit http://stackoverflow.com/tags/dart

To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
Alexandre Ardhuin
2015-12-15 09:25:26 UTC
Permalink
You can spawn multiple isolates (independent workers that are similar to
threads but don't share memory, communicating only via messages).

See
https://api.dartlang.org/1.13.0/dart-isolate/dart-isolate-library.html
https://api.dartlang.org/1.13.0/dart-io/Platform/numberOfProcessors.html

Alexandre
Post by Jan Mostert
Hi, I'm busy investigating whether I can use Dart for a backend service on
a new project, but need to understand the threading model to know if it'll
work for me or not.
In Java I can do Runtime.getRuntime().availableProcessors() and then
start threads in proportion to the number of processors available to
utilize all CPUs / Cores on each machine which should give me great
throughput on IO-bounded operations.
What is the Dart Threading model? Does it follow a similar model to Java
or a model similar to NodeJS that has a single thread and an event loop?
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups
"Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an
--
For other discussions, see https://groups.google.com/a/dartlang.org/

For HOWTO questions, visit http://stackoverflow.com/tags/dart

To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
Jan Mostert
2015-12-15 13:47:14 UTC
Permalink
Thanks Alexandre!
I've read through the docs + some examples and it seems Isolates will cater
for the majority of my multithreading needs.

How would one implement something like an AtomicLong or AtomicHashMap that
allows concurrent read / writes in a synchronized fashion?
One could always keep that data in an ACID compliant DB, but that's a lot
of overhead.
Post by Alexandre Ardhuin
You can spawn multiple isolates (independent workers that are similar to
threads but don't share memory, communicating only via messages).
See
https://api.dartlang.org/1.13.0/dart-isolate/dart-isolate-library.html
https://api.dartlang.org/1.13.0/dart-io/Platform/numberOfProcessors.html
Alexandre
Post by Jan Mostert
Hi, I'm busy investigating whether I can use Dart for a backend service
on a new project, but need to understand the threading model to know if
it'll work for me or not.
In Java I can do Runtime.getRuntime().availableProcessors() and then
start threads in proportion to the number of processors available to
utilize all CPUs / Cores on each machine which should give me great
throughput on IO-bounded operations.
What is the Dart Threading model? Does it follow a similar model to Java
or a model similar to NodeJS that has a single thread and an event loop?
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups
"Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups
"Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an
--
For other discussions, see https://groups.google.com/a/dartlang.org/

For HOWTO questions, visit http://stackoverflow.com/tags/dart

To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
Anders Holmgren
2015-12-16 05:42:46 UTC
Permalink
You don't need any synchronisation primitives. Isolates is more like an
Actor model. You pass messages between isolates.

Dart doesn't support multiple threads sharing memory so it doesn't have any
of those sorts of synchronisation primitives
Post by Jan Mostert
Thanks Alexandre!
I've read through the docs + some examples and it seems Isolates will
cater for the majority of my multithreading needs.
How would one implement something like an AtomicLong or AtomicHashMap that
allows concurrent read / writes in a synchronized fashion?
One could always keep that data in an ACID compliant DB, but that's a lot
of overhead.
Post by Alexandre Ardhuin
You can spawn multiple isolates (independent workers that are similar to
threads but don't share memory, communicating only via messages).
See
https://api.dartlang.org/1.13.0/dart-isolate/dart-isolate-library.html
https://api.dartlang.org/1.13.0/dart-io/Platform/numberOfProcessors.html
Alexandre
Post by Jan Mostert
Hi, I'm busy investigating whether I can use Dart for a backend service
on a new project, but need to understand the threading model to know if
it'll work for me or not.
In Java I can do Runtime.getRuntime().availableProcessors() and then
start threads in proportion to the number of processors available to
utilize all CPUs / Cores on each machine which should give me great
throughput on IO-bounded operations.
What is the Dart Threading model? Does it follow a similar model to Java
or a model similar to NodeJS that has a single thread and an event loop?
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to
http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google
Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups
"Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an
--
For other discussions, see https://groups.google.com/a/dartlang.org/

For HOWTO questions, visit http://stackoverflow.com/tags/dart

To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
Jan Mostert
2015-12-16 11:07:16 UTC
Permalink
"You don't need any synchronisation primitives"

I probably don't, will do some prototyping to see if Dart Isolates are
performant enough for my needs.
Thanks for the replies!

Interesting article comparing Akka to NodeJS to Java with Threads and
Futures and Dart and Go:
http://java-is-the-new-c.blogspot.co.za/2014/06/java-concurrency-learning-from-nodejs.html
Post by Anders Holmgren
You don't need any synchronisation primitives. Isolates is more like an
Actor model. You pass messages between isolates.
Dart doesn't support multiple threads sharing memory so it doesn't have
any of those sorts of synchronisation primitives
Post by Jan Mostert
Thanks Alexandre!
I've read through the docs + some examples and it seems Isolates will
cater for the majority of my multithreading needs.
How would one implement something like an AtomicLong or AtomicHashMap
that allows concurrent read / writes in a synchronized fashion?
One could always keep that data in an ACID compliant DB, but that's a lot
of overhead.
You can spawn multiple isolates (independent workers that are similar to
Post by Jan Mostert
Post by Alexandre Ardhuin
threads but don't share memory, communicating only via messages).
See
https://api.dartlang.org/1.13.0/dart-isolate/dart-isolate-library.html
https://api.dartlang.org/1.13.0/dart-io/Platform/numberOfProcessors.html
Alexandre
Post by Jan Mostert
Hi, I'm busy investigating whether I can use Dart for a backend service
on a new project, but need to understand the threading model to know if
it'll work for me or not.
In Java I can do Runtime.getRuntime().availableProcessors() and then
start threads in proportion to the number of processors available to
utilize all CPUs / Cores on each machine which should give me great
throughput on IO-bounded operations.
What is the Dart Threading model? Does it follow a similar model to
Java or a model similar to NodeJS that has a single thread and an event
loop?
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to
http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google
Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to
http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google
Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups
"Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an
--
For other discussions, see https://groups.google.com/a/dartlang.org/

For HOWTO questions, visit http://stackoverflow.com/tags/dart

To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
Loading...