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.

73 lines
2.9 KiB

6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 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. ## Quickstart
  12. git clone https://git.syndicate-lang.org/syndicate-lang/syndicate-java
  13. ant jar
  14. Then, if you'd like to run the simple million-actor/200-message
  15. benchmark discussed below, run `make ziprun`.
  16. ## Surprisingly fast
  17. It's quite interesting all by itself, though: it's *very* fast and
  18. able to use all the cores in a machine very effectively. For example:
  19. $ java ... ...example2.Main 1000000 200
  20. 2021-05-10 11:02:35.087 INFO Actor(1) Available processors: 48
  21. 2021-05-10 11:02:38.573 INFO Actor(1) Start
  22. 2021-05-10 11:02:44.161 INFO Actor(1) Stop after 200000000 messages; 4.8 seconds, 41999160.0 Hz
  23. That little benchmark has one million actors, each sending 200
  24. messages to its neighbour in a ring, on my AMD 48-core machine. The
  25. whole workload, 200 million messages, is delivered in under 5 seconds;
  26. or, about 40 million messages per second. I was surprised that such a
  27. simple system was able to perform so well.
  28. Here's that same benchmark run on a single core:
  29. $ taskset -c 0 java ... ...example2.Main 1000000 200
  30. 2021-05-10 11:07:42.104 INFO Actor(1) Available processors: 1
  31. 2021-05-10 11:07:47.826 INFO Actor(1) Start
  32. 2021-05-10 11:08:52.078 INFO Actor(1) Stop after 200000000 messages; 63.5 seconds, 3149903.9 Hz
  33. That's just over 3 million messages per second on a single core. Neat, huh?
  34. ## Surprisingly simple
  35. It's also only ~730 lines of code:
  36. ```
  37. ~/src/syndicate-java$ cloc src/main/java/
  38. 12 text files.
  39. 12 unique files.
  40. 0 files ignored.
  41. github.com/AlDanial/cloc v 1.86 T=0.01 s (965.7 files/s, 69128.5 lines/s)
  42. -------------------------------------------------------------------------------
  43. Language files blank comment code
  44. -------------------------------------------------------------------------------
  45. Java 12 126 6 727
  46. -------------------------------------------------------------------------------
  47. SUM: 12 126 6 727
  48. -------------------------------------------------------------------------------
  49. ```
  50. ## Next steps
  51. Next steps are to implement proper Dataspace model entities, with
  52. assertions and facets etc., and then build an actual Dataspace to go
  53. with it. I'll be trying to reuse as much of this implementation style
  54. as possible since it performs so well.