Skip to content

Commit

Permalink
Use .NET threadpool scheduler (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
xqrzd authored Jun 25, 2021
1 parent b8b9421 commit 9198a78
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 25 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ name: CI
on: [push]

env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_CLI_TELEMETRY_OPTOUT: 1

jobs:
Expand Down
42 changes: 18 additions & 24 deletions src/Knet.Kudu.Client/KuduClientOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,27 @@
using System.Collections.Generic;
using System.IO.Pipelines;
using Knet.Kudu.Client.Connection;
using Pipelines.Sockets.Unofficial;

namespace Knet.Kudu.Client
{
public class KuduClientOptions
{
private static readonly PipeOptions _defaultSendOptions = new(
readerScheduler: PipeScheduler.ThreadPool,
writerScheduler: PipeScheduler.ThreadPool,
pauseWriterThreshold: 1024 * 1024 * 4, // 4MB
resumeWriterThreshold: 1024 * 1024 * 2, // 2MB
minimumSegmentSize: 4096,
useSynchronizationContext: false);

private static readonly PipeOptions _defaultReceiveOptions = new(
readerScheduler: PipeScheduler.ThreadPool,
writerScheduler: PipeScheduler.ThreadPool,
pauseWriterThreshold: 1024 * 1024 * 128, // 128MB
resumeWriterThreshold: 1024 * 1024 * 64, // 64MB
minimumSegmentSize: 1024 * 256,
useSynchronizationContext: false);

public IReadOnlyList<HostAndPort> MasterAddresses { get; }

public TimeSpan DefaultAdminOperationTimeout { get; }
Expand All @@ -29,29 +44,8 @@ public KuduClientOptions(
DefaultAdminOperationTimeout = defaultAdminOperationTimeout;
DefaultOperationTimeout = defaultOperationTimeout;

SendPipeOptions = sendPipeOptions ?? StaticContext.DefaultSendOptions;
ReceivePipeOptions = receivePipeOptions ?? StaticContext.DefaultReceiveOptions;
}

private static class StaticContext
{
// Place these here so we don't instantiate them too early.

internal static readonly PipeOptions DefaultSendOptions = new PipeOptions(
readerScheduler: DedicatedThreadPoolPipeScheduler.Default,
writerScheduler: DedicatedThreadPoolPipeScheduler.Default,
pauseWriterThreshold: 1024 * 1024 * 4, // 4MB
resumeWriterThreshold: 1024 * 1024 * 2, // 2MB
minimumSegmentSize: 4096,
useSynchronizationContext: false);

internal static readonly PipeOptions DefaultReceiveOptions = new PipeOptions(
readerScheduler: DedicatedThreadPoolPipeScheduler.Default,
writerScheduler: DedicatedThreadPoolPipeScheduler.Default,
pauseWriterThreshold: 1024 * 1024 * 256, // 256MB
resumeWriterThreshold: 1024 * 1024 * 128, // 128MB
minimumSegmentSize: 1024 * 256,
useSynchronizationContext: false);
SendPipeOptions = sendPipeOptions ?? _defaultSendOptions;
ReceivePipeOptions = receivePipeOptions ?? _defaultReceiveOptions;
}
}
}

0 comments on commit 9198a78

Please sign in to comment.