Async/await behaviour and CPU affinity #95132
Unanswered
enclave-alistair
asked this question in
General
Replies: 1 comment 2 replies
-
... have you considered something like spinning up multiple versions of the application, each one bound to only one CPU by OS utilities? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've got a dotnet app that does a lot of high-throughput IO, and we use async/await everywhere to scale the throughput to a large number of active sessions (mostly TCP and UDP, with some P/Invokes on the other end). Whatever the case, there's a bunch of buffers involved, plus encryption and so on.
I found myself wondering, if I await an operation, is there any way to ask the completion handler of the task to execute on the same CPU as the initiating operation, to ensure the relevant memory remains in the L1/L2 cache for the CPU?
I imagine the answer will be no, since #21363 indicates thread affinity is not supported.
My dream I suppose is to be able to create a custom threadpool with affinity set, so there's effectively one threadpool per CPU, and for awaitable tasks to resume on the same CPU-bound threadpool that initiated the operation.
I can also imagine that the .NET team has already looked into this and said "it wouldn't help, the switch between threads is already bad enough that the extra affinity doesn't bring any gains".
Beta Was this translation helpful? Give feedback.
All reactions