Java implementation of Dataspaces and Syndicate.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.7 KiB

3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
  1. # A surprisingly fast, surprisingly simple Actor library for Java
  2. As part of my research work on
  3. [Syndicate](https://syndicate-lang.org), in 2020 I built this simple
  4. Actor library in and for Java.
  5. It's a hybrid of Erlang-style and E-style Actor models: Erlang-style
  6. in that it includes monitors and links, and E-style in that it peers
  7. denote targets for messages via references to individual *objects*
  8. with an actor. Actors are thus similar to E's *vats*.
  9. So far, I've limited myself to implementing a straightforward Actor
  10. system, not including Dataspace or Syndicate primitives.
  11. ## Surprisingly fast
  12. It's quite interesting all by itself, though: it's *very* fast and
  13. able to use all the cores in a machine very effectively. For example:
  14. $ java ... ...example2.Main 1000000 200
  15. 2021-05-10 11:02:35.087 INFO Actor(1) Available processors: 48
  16. 2021-05-10 11:02:38.573 INFO Actor(1) Start
  17. 2021-05-10 11:02:44.161 INFO Actor(1) Stop after 200000000 messages; 4.8 seconds, 41999160.0 Hz
  18. That little benchmark has one million actors, each sending 200
  19. messages to its neighbour in a ring, on my AMD 48-core machine. The
  20. whole workload, 200 million messages, is delivered in under 5 seconds;
  21. or, about 40 million messages per second. I was surprised that such a
  22. simple system was able to perform so well.
  23. Here's that same benchmark run on a single core:
  24. $ taskset -c 0 java ... ...example2.Main 1000000 200
  25. 2021-05-10 11:07:42.104 INFO Actor(1) Available processors: 1
  26. 2021-05-10 11:07:47.826 INFO Actor(1) Start
  27. 2021-05-10 11:08:52.078 INFO Actor(1) Stop after 200000000 messages; 63.5 seconds, 3149903.9 Hz
  28. That's just over 3 million messages per second on a single core. Neat, huh?
  29. ## Surprisingly simple
  30. It's also only ~730 lines of code:
  31. ```
  32. ~/src/syndicate-java$ cloc src/main/java/
  33. 12 text files.
  34. 12 unique files.
  35. 0 files ignored.
  36. github.com/AlDanial/cloc v 1.86 T=0.01 s (965.7 files/s, 69128.5 lines/s)
  37. -------------------------------------------------------------------------------
  38. Language files blank comment code
  39. -------------------------------------------------------------------------------
  40. Java 12 126 6 727
  41. -------------------------------------------------------------------------------
  42. SUM: 12 126 6 727
  43. -------------------------------------------------------------------------------
  44. ```
  45. ## Next steps
  46. Next steps are to implement proper Dataspace model entities, with
  47. assertions and facets etc., and then build an actual Dataspace to go
  48. with it. I'll be trying to reuse as much of this implementation style
  49. as possible since it performs so well.