<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div><blockquote type="cite" class=""><div class="">On 11 Apr 2017, at 23:37, Greg Parker via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="font-family: Helvetica; font-size: 18px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" class=""><div class=""><br class="Apple-interchange-newline">On Apr 11, 2017, at 9:10 AM, Gerard Iglesias via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><div class="">Thanx for the link on this…</div><div class=""><br class=""></div><div class=""><div class="">I am experimenting the use of dispatch queue to mimic somme Actor Model things and it is not a bad idea, dispatch queue are perfect for that.<br class=""></div></div><div class=""><br class=""></div><div class="">I wonder what is the scalability of the Dispatch layer, are we able to create a bunch of dispatch queue without putting the system on its knees ? I will do tests</div></div></div></div></blockquote><br class=""></div><div style="font-family: Helvetica; font-size: 18px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">Dispatch queues are intended to be cheap, comparable to a pthread_mutex IIRC.</div><div style="font-family: Helvetica; font-size: 18px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 18px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">The limited resource are the top-level global queues, DispatchQueue.main and DispatchQueue.global(…). There are a limited number of threads available to service concurrent items on those queues (around 500 threads on macOS and iOS, IIRC). If too many concurrent work items are pushed into the global queues at one time then the process may deadlock when dispatch exhausts its thread pool.</div></div></blockquote><br class=""></div><div>These can be accessed via sysctl, for future reference:</div><div><br class=""></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">$ sysctl kern.wq_max_threads kern.wq_max_constrained_threads&nbsp;</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">kern.wq_max_threads: 512</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">kern.wq_max_constrained_threads: 64</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div></div>The limit of 64 applies to lower-priority items (which is the default, IIRC) so you may find that you hit the 64 limit faster than you hit the 512 limit.<div class=""><br class=""></div><div class="">Alex</div></body></html>