Dispatch + Blocking Calls


#1

Something to keep in mind… once SR-2905 <https://bugs.swift.org/browse/SR-2905> is resolved, it will be feasible to write Linux server applications in a synchronous manner.

How does this work? Dispatch work items are scheduled onto a pool of kernel threads. If a work item makes a blocking system call, the kernel thread will be blocked. Ideally, the work item scheduler will start a new kernel thread to take the place of the blocked thread. This is only possible if the scheduler can be triggered at the moment the blocking system call is made. A Linux kernel module is required for this to work in Swift.

This ideal threading model is the main selling point of Go. Go developers can write their code in a synchronous manner without any performance tradeoff. (You might be wondering why Go does not need a kernel module. The reason is all the system calls go through the Go runtime before reaching the kernel.)

Personally, I am very excited for the day that this kernel module is released. Swift will truly be the best programming language in nearly every regard.

Darren


(Jean-Daniel) #2

The main benefit of GCD and worker threads is that as the threads are managed by the kernel, it can accommodate thread allocation and io scheduling by considering the system load as a whole, and not only the process load.
I’m not familiar with go enough to know how the runtime cope with this, but from the description it look like it don't care about other processes when it managed goroutines.

···

Le 31 oct. 2016 à 09:21, Darren Mo via swift-server-dev <swift-server-dev@swift.org> a écrit :

Something to keep in mind… once SR-2905 <https://bugs.swift.org/browse/SR-2905> is resolved, it will be feasible to write Linux server applications in a synchronous manner.

How does this work? Dispatch work items are scheduled onto a pool of kernel threads. If a work item makes a blocking system call, the kernel thread will be blocked. Ideally, the work item scheduler will start a new kernel thread to take the place of the blocked thread. This is only possible if the scheduler can be triggered at the moment the blocking system call is made. A Linux kernel module is required for this to work in Swift.

This ideal threading model is the main selling point of Go. Go developers can write their code in a synchronous manner without any performance tradeoff. (You might be wondering why Go does not need a kernel module. The reason is all the system calls go through the Go runtime before reaching the kernel.)


#3

You are right that the Go runtime does not care about system load. I suppose it was designed for server applications running in Docker containers or virtual machines. In this world, system load does not matter because a chunk of system resources will be allocated exclusively to the application.

···

On Oct 31, 2016, at 2:25 PM, Jean-Daniel <dev@xenonium.com> wrote:

Le 31 oct. 2016 à 09:21, Darren Mo via swift-server-dev <swift-server-dev@swift.org> a écrit :

Something to keep in mind… once SR-2905 is resolved, it will be feasible to write Linux server applications in a synchronous manner.

How does this work? Dispatch work items are scheduled onto a pool of kernel threads. If a work item makes a blocking system call, the kernel thread will be blocked. Ideally, the work item scheduler will start a new kernel thread to take the place of the blocked thread. This is only possible if the scheduler can be triggered at the moment the blocking system call is made. A Linux kernel module is required for this to work in Swift.

This ideal threading model is the main selling point of Go. Go developers can write their code in a synchronous manner without any performance tradeoff. (You might be wondering why Go does not need a kernel module. The reason is all the system calls go through the Go runtime before reaching the kernel.)

The main benefit of GCD and worker threads is that as the threads are managed by the kernel, it can accommodate thread allocation and io scheduling by considering the system load as a whole, and not only the process load.
I’m not familiar with go enough to know how the runtime cope with this, but from the description it look like it don't care about other processes when it managed goroutines.