Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bryanmikaelian/clj-virtual-threads
An experiment with Java21 Virtual Threads and Clojure
https://github.com/bryanmikaelian/clj-virtual-threads
clojure jvm virtual-threads-java-21
Last synced: about 1 month ago
JSON representation
An experiment with Java21 Virtual Threads and Clojure
- Host: GitHub
- URL: https://github.com/bryanmikaelian/clj-virtual-threads
- Owner: bryanmikaelian
- Created: 2024-07-30T20:41:41.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2024-08-19T14:52:01.000Z (3 months ago)
- Last Synced: 2024-09-29T17:21:57.723Z (about 2 months ago)
- Topics: clojure, jvm, virtual-threads-java-21
- Language: Clojure
- Homepage:
- Size: 16.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# clj-virtual-threads
An experiment with Java21 Virtual Threads and Clojure. Both examples just update an `atom` counter over 100000 threads, comparing the execution time between a virtual thread and a "real" thread.## Disclaimer
This was a very quick thought experiment but there are some issues. Take these numbers with a grain of salt [See this hacker news thread](https://news.ycombinator.com/item?id=41127344)
## Running
Using the Clojure [CLI](https://clojure.org/guides/deps_and_cli), you can run this program like so:
```sh
clj src/main.clj
```## Results
### M3 Mac
![CleanShot 2024-07-31 at 10 49 58](https://github.com/user-attachments/assets/bdcb6af4-fae5-4fbc-97e6-e0da467f7846)```
count: 100000
virtual start time (ms): 1722446540075
virtual end time (ms): 1722446540306
virtual elapsed time (ms): 231
count: 100000
real start time (ms): 1722446540311
real end time (ms): 1722446543667
real elapsed time (ms): 3356
```### Intel Mac
```
count: 100000
virtual start time (ms): 1722449512852
virtual end time (ms): 1722449513318
virtual elapsed time (ms): 466
count: 100000
real start time (ms): 1722449513330
real end time (ms): 1722449520618
real elapsed time (ms): 7288
```