Skip to content

Commit

Permalink
Wording change
Browse files Browse the repository at this point in the history
  • Loading branch information
andersmurphy committed May 30, 2024
1 parent ab183e5 commit 1bb46b6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@
</span><span class="dim">;; Execution time lower quantile : 165.292587 ms <span class="dim">&#40;</span> 2.5%<span class="dim">&#41;</span>
</span><span class="dim">;; Execution time upper quantile : 215.966794 ms <span class="dim">&#40;</span>97.5%<span class="dim">&#41;</span>
</span><span class="dim">;; Overhead used : 1.845282 ns
</span></code></pre><p>With 50000 virtual threads <code>pmap</code>'s execution time mean is 189.313904 ms. Roughly, 5x faster than the dynamic var version and a similar speed to the scoped values version.</p><p>My take away is: you probably don't need dynamic scope. Instead, pass the context explicitly. If you really think you need dynamic scope and are using a large number of virtual threads favour scoped values over dynamic vars. That being said scoped values only work with structured concurrency, so if you are using things like <code>Executor</code> and <code>CompletionService</code> you'll have to either pass context explicitly or use dynamic vars.</p><p>The full example <a href='https://github.com/andersmurphy/clj-cookbook/tree/master/virtual-threads/dynamic-var-perf'>project can be found here</a>.</p><p><strong>Further Reading:</strong></p><ul><li><a href='https://openjdk.org/jeps/446'>JEP 446: Scoped Values</a></li><li><a href='https://openjdk.org/jeps/462'>JEP 462: Structured Concurrency</a></li><li><a href='https://andersmurphy.com/2024/05/06/clojure-managing-throughput-with-virtual-threads.html'>Clojure: managing throughput with virtual threads</a></li><li><a href='https://andersmurphy.com/2024/05/14/clojure-structured-concurrency-and-scoped-values.html'>Clojure: structured concurrency and scoped values</a></li></ul></article><footer><p>© 2015-2024 Anders Murphy</p></footer></main></body></html>
</span></code></pre><p>With 50000 virtual threads <code>pmap</code>'s execution time mean is 189.313904 ms. Roughly, 5x faster than the dynamic var version and a similar speed to the scoped values version.</p><p>My take away is: you probably don't need dynamic scope. Instead, pass the context explicitly. If you really think you need dynamic scope and are using a large number of virtual threads favour scoped values over dynamic vars. That being said scoped values thread conveyance only works with structured concurrency, so if you are using things like <code>Executor</code> and <code>CompletionService</code> you'll have to either pass context explicitly or use dynamic vars.</p><p>The full example <a href='https://github.com/andersmurphy/clj-cookbook/tree/master/virtual-threads/dynamic-var-perf'>project can be found here</a>.</p><p><strong>Further Reading:</strong></p><ul><li><a href='https://openjdk.org/jeps/446'>JEP 446: Scoped Values</a></li><li><a href='https://openjdk.org/jeps/462'>JEP 462: Structured Concurrency</a></li><li><a href='https://andersmurphy.com/2024/05/06/clojure-managing-throughput-with-virtual-threads.html'>Clojure: managing throughput with virtual threads</a></li><li><a href='https://andersmurphy.com/2024/05/14/clojure-structured-concurrency-and-scoped-values.html'>Clojure: structured concurrency and scoped values</a></li></ul></article><footer><p>© 2015-2024 Anders Murphy</p></footer></main></body></html>
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ If your function call stack is shallow then, it can be simpler to just pass the

With 50000 virtual threads `pmap`'s execution time mean is 189.313904 ms. Roughly, 5x faster than the dynamic var version and a similar speed to the scoped values version.

My take away is: you probably don't need dynamic scope. Instead, pass the context explicitly. If you really think you need dynamic scope and are using a large number of virtual threads favour scoped values over dynamic vars. That being said scoped values only work with structured concurrency, so if you are using things like `Executor` and `CompletionService` you'll have to either pass context explicitly or use dynamic vars.
My take away is: you probably don't need dynamic scope. Instead, pass the context explicitly. If you really think you need dynamic scope and are using a large number of virtual threads favour scoped values over dynamic vars. That being said scoped values thread conveyance only works with structured concurrency, so if you are using things like `Executor` and `CompletionService` you'll have to either pass context explicitly or use dynamic vars.

The full example [project can be found here](https://github.com/andersmurphy/clj-cookbook/tree/master/virtual-threads/dynamic-var-perf).

Expand Down

0 comments on commit 1bb46b6

Please sign in to comment.