[swift-users] Swift Concurrency and Actor model
Alex Blewitt
alblue at apple.com
Wed Apr 12 04:57:13 CDT 2017
> On 11 Apr 2017, at 23:37, Greg Parker via swift-users <swift-users at swift.org> wrote:
>
>>
>> On Apr 11, 2017, at 9:10 AM, Gerard Iglesias via swift-users <swift-users at swift.org <mailto:swift-users at swift.org>> wrote:
>>
>> Thanx for the link on this…
>>
>> 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.
>>
>> 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
>
> Dispatch queues are intended to be cheap, comparable to a pthread_mutex IIRC.
>
> 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.
These can be accessed via sysctl, for future reference:
$ sysctl kern.wq_max_threads kern.wq_max_constrained_threads
kern.wq_max_threads: 512
kern.wq_max_constrained_threads: 64
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.
Alex
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170412/9a95efe8/attachment.html>
More information about the swift-users
mailing list