The UMS (User-Mode Scheduling) is a feature added to Windows 7 and later, but only works in 64bit versions. It enable applications to schedule their own threads in their own custom policy. In this way, it provides the capability of fiber/coroutine, but in the form of native thread.
We compare the performance of UMS with those of native thread and fiber, using a very simple implementation.
-
Install CMake and Visual Studio in 64bit Windows (7 or later).
-
In cmd, generate the VS project.
mkdir build
cd build
cmake ..
-
Open
Windows-UMS.sln
in Visual Studio. -
Choose
Release
+x64
configuration, andGenerate Solutions
- Run UMS version
Release\ms-example.exe <number-of-threads> <num-of-yields>
- Run Native thread version
Release\thread-example.exe <number-of-threads> <num-of-yields>
- Run Fiber version
Release\fiber-example.exe <number-of-threads> <num-of-yields>
On my laptop (Lenovo Thinkpad X270 with Intel i5-6200U and 8G memory), The average execution time for each yield is:
- 10-threads concurrency:
Number of yields | 100 | 1000 | 10000 | 100000 |
---|---|---|---|---|
Native thread | 1201ns | 633ns | 640ns | 632ns |
UMS | 2752ns | 400ns | 148ns | 118ns |
Fiber | 96ns | 105ns | 101ns | 88ns |
- 100-threads concurrency:
Number of yields | 100 | 1000 | 10000 | 100000 |
---|---|---|---|---|
Native thread | 769ns | 610ns | 601ns | 591ns |
UMS | 1428ns | 245ns | 152ns | 128ns |
Fiber | 130ns | 105ns | 102ns | 102ns |
- 1000-threads concurrency:
Number of yields | 100 | 1000 | 10000 | 100000 |
---|---|---|---|---|
Native thread | 941ns | 790ns | 793ns | 785ns |
UMS | 1400ns | 276ns | 146ns | 127ns |
Fiber | 175ns | 167ns | 177ns | 180ns |
Some of the code is adopted from pervognsen's gist.