You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This high CPU usage observed with the default thread config in DotNet is likely a problem others are encountering and may not be aware of
There likely needs to be an improvement made to the DotNet work stealing algorithm to reduce stealing when there is not enough work to go around to all the threads and/or there needs to be a tuning of how many threads to create
Video Review of Performance Improvement - YouTube
Click to view on YouTube
Test Setup
Rust Extension with Current Thread Runtime (default, but specified here)
Router with Max 1 Worker Thread, Max 1,000 (default) Completion Port Threads, DOTNET_ThreadPool_UnfairSemaphoreSpinLimit Unspecified
ThreadPool.SetMinThreads(1,1);ThreadPool.GetMaxThreads(outvarworkerThreads,outvarcompletionPortThreads);Console.WriteLine($"ThreadPool.GetMaxThreads returned {workerThreads} worker threads and {completionPortThreads} completion port threads");varresult=ThreadPool.SetMaxThreads(1,completionPortThreads);Console.WriteLine($"ThreadPool.SetMaxThreads returned {result}");ThreadPool.GetMaxThreads(outworkerThreads,outcompletionPortThreads);Console.WriteLine($"ThreadPool.GetMaxThreads returned {workerThreads} worker threads and {completionPortThreads} completion port threads");
Router with Max 32,767 (default) Worker Threads, Max 1 Completion Port Thread, DOTNET_ThreadPool_UnfairSemaphoreSpinLimit Unspecified
ThreadPool.SetMinThreads(1,1);ThreadPool.GetMaxThreads(outvarworkerThreads,outvarcompletionPortThreads);Console.WriteLine($"ThreadPool.GetMaxThreads returned {workerThreads} worker threads and {completionPortThreads} completion port threads");varresult=ThreadPool.SetMaxThreads(workerThreads,1);Console.WriteLine($"ThreadPool.SetMaxThreads returned {result}");ThreadPool.GetMaxThreads(outworkerThreads,outcompletionPortThreads);Console.WriteLine($"ThreadPool.GetMaxThreads returned {workerThreads} worker threads and {completionPortThreads} completion port threads");
Router with Max 12 Worker Threads, Max 1 Completion Port Thread, DOTNET_ThreadPool_UnfairSemaphoreSpinLimit Unspecified
ThreadPool.SetMinThreads(1,1);varresult=ThreadPool.SetMaxThreads(12,1);Console.WriteLine($"ThreadPool.SetMaxThreads returned {result}");
Note: Limiting worker threads to 25 drops CPU from 700% to 500-600%, then limiting worker threads to 20 drops CPU further from 500-600% to 300%, limiting to 2 drops CPU to 175%, and finally limiting to 1 drops CPU to 125%.
Motivations
Video Review of Performance Improvement - YouTube
Click to view on YouTube
Test Setup
LAMBDA_DISPATCH_RUNTIME=current_thread LAMBDA_DISPATCH_FORCE_DEADLINE=60 AWS_LAMBDA_FUNCTION_VERSION=\$LATEST AWS_LAMBDA_FUNCTION_MEMORY_SIZE=512 AWS_LAMBDA_FUNCTION_NAME=dogs AWS_LAMBDA_RUNTIME_API=localhost:5051 AWS_REGION=us-east-2 AWS_ACCESS_KEY_ID=test-access-key-id AWS_SECRET_ACCESS_KEY=test-secret-access-key AWS_SESSION_TOKEN=test-session-token cargo run --release --bin extension 2>&1 | tee extension.log
DOTNET_ThreadPool_UnfairSemaphoreSpinLimit=5 LAMBDA_DISPATCH_ChannelCount=10 LAMBDA_DISPATCH_MaxConcurrentCount=10 LAMBDA_DISPATCH_AllowInsecureControlChannel=true LAMBDA_DISPATCH_PreferredControlChannelScheme=http LAMBDA_DISPATCH_FunctionName=dogs AWS_LAMBDA_SERVICE_URL=http://localhost:5051 AWS_REGION=us-east-2 AWS_ACCESS_KEY_ID=test-access-key-id AWS_SECRET_ACCESS_KEY=test-secret-access-key AWS_SESSION_TOKEN=test-session-token src/PwrDrvr.LambdaDispatch.Router/bin/Release/net8.0/PwrDrvr.LambdaDispatch.Router 2>&1 | tee router.log
oha -c 10 -z 60s http://127.0.0.1:5001/ping
Test Cases
Router with Default ThreadPool Threads,
DOTNET_ThreadPool_UnfairSemaphoreSpinLimit
not SpecifiedLAMBDA_DISPATCH_ChannelCount=10 LAMBDA_DISPATCH_MaxConcurrentCount=10 LAMBDA_DISPATCH_AllowInsecureControlChannel=true LAMBDA_DISPATCH_PreferredControlChannelScheme=http LAMBDA_DISPATCH_FunctionName=dogs AWS_LAMBDA_SERVICE_URL=http://localhost:5051 AWS_REGION=us-east-2 AWS_ACCESS_KEY_ID=test-access-key-id AWS_SECRET_ACCESS_KEY=test-secret-access-key AWS_SESSION_TOKEN=test-session-token src/PwrDrvr.LambdaDispatch.Router/bin/Release/net8.0/PwrDrvr.LambdaDispatch.Router 2>&1 | tee router.log
Router with Default ThreadPool Threads,
DOTNET_ThreadPool_UnfairSemaphoreSpinLimit=5
DOTNET_ThreadPool_UnfairSemaphoreSpinLimit=5 LAMBDA_DISPATCH_ChannelCount=10 LAMBDA_DISPATCH_MaxConcurrentCount=10 LAMBDA_DISPATCH_AllowInsecureControlChannel=true LAMBDA_DISPATCH_PreferredControlChannelScheme=http LAMBDA_DISPATCH_FunctionName=dogs AWS_LAMBDA_SERVICE_URL=http://localhost:5051 AWS_REGION=us-east-2 AWS_ACCESS_KEY_ID=test-access-key-id AWS_SECRET_ACCESS_KEY=test-secret-access-key AWS_SESSION_TOKEN=test-session-token src/PwrDrvr.LambdaDispatch.Router/bin/Release/net8.0/PwrDrvr.LambdaDispatch.Router 2>&1 | tee router.log
Router with Max 1 Worker Thread, Max 1,000 (default) Completion Port Threads,
DOTNET_ThreadPool_UnfairSemaphoreSpinLimit
UnspecifiedLAMBDA_DISPATCH_ChannelCount=10 LAMBDA_DISPATCH_MaxConcurrentCount=10 LAMBDA_DISPATCH_AllowInsecureControlChannel=true LAMBDA_DISPATCH_PreferredControlChannelScheme=http LAMBDA_DISPATCH_FunctionName=dogs AWS_LAMBDA_SERVICE_URL=http://localhost:5051 AWS_REGION=us-east-2 AWS_ACCESS_KEY_ID=test-access-key-id AWS_SECRET_ACCESS_KEY=test-secret-access-key AWS_SESSION_TOKEN=test-session-token src/PwrDrvr.LambdaDispatch.Router/bin/Release/net8.0/PwrDrvr.LambdaDispatch.Router 2>&1 | tee router.log
Router with Max 32,767 (default) Worker Threads, Max 1 Completion Port Thread,
DOTNET_ThreadPool_UnfairSemaphoreSpinLimit
UnspecifiedLAMBDA_DISPATCH_ChannelCount=10 LAMBDA_DISPATCH_MaxConcurrentCount=10 LAMBDA_DISPATCH_AllowInsecureControlChannel=true LAMBDA_DISPATCH_PreferredControlChannelScheme=http LAMBDA_DISPATCH_FunctionName=dogs AWS_LAMBDA_SERVICE_URL=http://localhost:5051 AWS_REGION=us-east-2 AWS_ACCESS_KEY_ID=test-access-key-id AWS_SECRET_ACCESS_KEY=test-secret-access-key AWS_SESSION_TOKEN=test-session-token src/PwrDrvr.LambdaDispatch.Router/bin/Release/net8.0/PwrDrvr.LambdaDispatch.Router 2>&1 | tee router.log
Router with Max 12 Worker Threads, Max 1 Completion Port Thread,
DOTNET_ThreadPool_UnfairSemaphoreSpinLimit
UnspecifiedNote: Limiting worker threads to
25
drops CPU from 700% to 500-600%, then limiting worker threads to20
drops CPU further from 500-600% to 300%, limiting to2
drops CPU to 175%, and finally limiting to1
drops CPU to 125%.LAMBDA_DISPATCH_ChannelCount=10 LAMBDA_DISPATCH_MaxConcurrentCount=10 LAMBDA_DISPATCH_AllowInsecureControlChannel=true LAMBDA_DISPATCH_PreferredControlChannelScheme=http LAMBDA_DISPATCH_FunctionName=dogs AWS_LAMBDA_SERVICE_URL=http://localhost:5051 AWS_REGION=us-east-2 AWS_ACCESS_KEY_ID=test-access-key-id AWS_SECRET_ACCESS_KEY=test-secret-access-key AWS_SESSION_TOKEN=test-session-token src/PwrDrvr.LambdaDispatch.Router/bin/Release/net8.0/PwrDrvr.LambdaDispatch.Router 2>&1 | tee router.log
Router with Max 1 Worker Thread, Max 1 Completion Port Thread,
DOTNET_ThreadPool_UnfairSemaphoreSpinLimit
UnspecifiedLAMBDA_DISPATCH_ChannelCount=10 LAMBDA_DISPATCH_MaxConcurrentCount=10 LAMBDA_DISPATCH_AllowInsecureControlChannel=true LAMBDA_DISPATCH_PreferredControlChannelScheme=http LAMBDA_DISPATCH_FunctionName=dogs AWS_LAMBDA_SERVICE_URL=http://localhost:5051 AWS_REGION=us-east-2 AWS_ACCESS_KEY_ID=test-access-key-id AWS_SECRET_ACCESS_KEY=test-secret-access-key AWS_SESSION_TOKEN=test-session-token src/PwrDrvr.LambdaDispatch.Router/bin/Release/net8.0/PwrDrvr.LambdaDispatch.Router 2>&1 | tee router.log
The text was updated successfully, but these errors were encountered: