示例#1
0
 /// <summary>
 /// Creates gRPC environment.
 /// </summary>
 private GrpcEnvironment()
 {
     GrpcNativeInit();
     completionRegistry = new CompletionRegistry(this);
     threadPool         = new GrpcThreadPool(this, THREAD_POOL_SIZE);
     threadPool.Start();
 }
示例#2
0
        private void ThreadBody(int iterations, int payloadSize)
        {
            // TODO(jtattermusch): parametrize by number of pending completions.
            // TODO(jtattermusch): parametrize by cached/non-cached BatchContextSafeHandle

            var completionRegistry = new CompletionRegistry(environment);
            var cq   = CompletionQueueSafeHandle.CreateAsync(completionRegistry);
            var call = CreateFakeCall(cq);

            var sendCompletionCallback = new NopSendCompletionCallback();
            var payload    = new byte[payloadSize];
            var writeFlags = default(WriteFlags);

            var stopwatch = Stopwatch.StartNew();

            for (int i = 0; i < iterations; i++)
            {
                call.StartSendMessage(sendCompletionCallback, payload, writeFlags, false);
                var callback = completionRegistry.Extract(completionRegistry.LastRegisteredKey);
                callback.OnComplete(true);
            }
            stopwatch.Stop();
            Console.WriteLine("Elapsed millis: " + stopwatch.ElapsedMilliseconds);

            cq.Dispose();
        }
示例#3
0
 /// <summary>
 /// Creates gRPC environment.
 /// </summary>
 private GrpcEnvironment()
 {
     GrpcNativeInit();
     completionRegistry = new CompletionRegistry(this);
     threadPool         = new GrpcThreadPool(this, GetThreadPoolSizeOrDefault());
     threadPool.Start();
 }
 public void RegisterExtract()
 {
     RunConcurrent(() => {
         CompletionRegistry sharedRegistry = UseSharedRegistry ? new CompletionRegistry(Environment, () => BatchContextSafeHandle.Create(), () => RequestCallContextSafeHandle.Create()) : null;
         RunBody(sharedRegistry);
     });
 }
示例#5
0
 /// <summary>
 /// Creates gRPC environment.
 /// </summary>
 private GrpcEnvironment()
 {
     NativeLogRedirector.Redirect();
     GrpcNativeInit();
     completionRegistry = new CompletionRegistry(this);
     threadPool         = new GrpcThreadPool(this, _threadPoolSize);
     threadPool.Start();
 }
        public void Run(int threadCount, int iterations, bool useSharedRegistry)
        {
            Console.WriteLine(string.Format("CompletionRegistryBenchmark: threads={0}, iterations={1}, useSharedRegistry={2}", threadCount, iterations, useSharedRegistry));
            CompletionRegistry sharedRegistry = useSharedRegistry ? new CompletionRegistry(environment, () => BatchContextSafeHandle.Create(), () => RequestCallContextSafeHandle.Create()) : null;
            var threadedBenchmark             = new ThreadedBenchmark(threadCount, () => ThreadBody(iterations, sharedRegistry));

            threadedBenchmark.Run();
            // TODO: parametrize by number of pending completions
        }
示例#7
0
 /// <summary>
 /// Creates gRPC environment.
 /// </summary>
 private GrpcEnvironment()
 {
     GrpcLog.RedirectNativeLogs(Console.Error);
     grpcsharp_init();
     completionRegistry = new CompletionRegistry(this);
     threadPool         = new GrpcThreadPool(this, THREAD_POOL_SIZE);
     threadPool.Start();
     // TODO: use proper logging here
     Console.WriteLine("GRPC initialized.");
 }
示例#8
0
 /// <summary>
 /// Creates gRPC environment.
 /// </summary>
 private GrpcEnvironment()
 {
     NativeLogRedirector.Redirect();
     grpcsharp_init();
     completionRegistry = new CompletionRegistry(this);
     threadPool         = new GrpcThreadPool(this, THREAD_POOL_SIZE);
     threadPool.Start();
     // TODO: use proper logging here
     Logger.Info("gRPC initialized.");
 }
        private void RunBody(CompletionRegistry optionalSharedRegistry)
        {
            var completionRegistry = optionalSharedRegistry ?? new CompletionRegistry(Environment, () => throw new NotImplementedException(), () => throw new NotImplementedException());
            var ctx = BatchContextSafeHandle.Create();

            for (int i = 0; i < Iterations; i++)
            {
                completionRegistry.Register(ctx.Handle, ctx);
                var callback = completionRegistry.Extract(ctx.Handle);
                // NOTE: we are not calling the callback to avoid disposing ctx.
            }
            ctx.Recycle();
        }
示例#10
0
        public void Setup()
        {
            var native = NativeMethods.Get();

            // nop the native-call via reflection
            NativeMethods.Delegates.grpcsharp_call_send_status_from_server_delegate nop = (CallSafeHandle call, BatchContextSafeHandle ctx, StatusCode statusCode, byte[] statusMessage, UIntPtr statusMessageLen, MetadataArraySafeHandle metadataArray, int sendEmptyInitialMetadata, byte[] optionalSendBuffer, UIntPtr optionalSendBufferLen, WriteFlags writeFlags) => {
                completionRegistry.Extract(ctx.Handle).OnComplete(true); // drain the dictionary as we go
                return(CallError.OK);
            };
            native.GetType().GetField(nameof(native.grpcsharp_call_send_status_from_server)).SetValue(native, nop);

            environment        = GrpcEnvironment.AddRef();
            metadata           = MetadataArraySafeHandle.Create(Metadata.Empty);
            completionRegistry = new CompletionRegistry(environment, () => environment.BatchContextPool.Lease(), () => throw new NotImplementedException());
            var cq = CompletionQueueSafeHandle.CreateAsync(completionRegistry);

            call = CreateFakeCall(cq);
        }
        private void ThreadBody(int iterations, CompletionRegistry optionalSharedRegistry)
        {
            var completionRegistry = optionalSharedRegistry ?? new CompletionRegistry(environment, () => throw new NotImplementedException(), () => throw new NotImplementedException());
            var ctx = BatchContextSafeHandle.Create();

            var stopwatch = Stopwatch.StartNew();

            for (int i = 0; i < iterations; i++)
            {
                completionRegistry.Register(ctx.Handle, ctx);
                var callback = completionRegistry.Extract(ctx.Handle);
                // NOTE: we are not calling the callback to avoid disposing ctx.
            }
            stopwatch.Stop();
            Console.WriteLine("Elapsed millis: " + stopwatch.ElapsedMilliseconds);

            ctx.Recycle();
        }
示例#12
0
        private void ThreadBody(int iterations)
        {
            var completionRegistry = new CompletionRegistry(environment);
            var ctx = BatchContextSafeHandle.Create();

            var stopwatch = Stopwatch.StartNew();

            for (int i = 0; i < iterations; i++)
            {
                completionRegistry.Register(ctx.Handle, ctx);
                var callback = completionRegistry.Extract(completionRegistry.LastRegisteredKey);
                // NOTE: we are not calling the callback to avoid disposing ctx.
            }
            stopwatch.Stop();
            Console.WriteLine("Elapsed millis: " + stopwatch.ElapsedMilliseconds);

            ctx.Dispose();
        }
示例#13
0
        private void ThreadBody(int iterations, int payloadSize)
        {
            var completionRegistry = new CompletionRegistry(environment, () => environment.BatchContextPool.Lease());
            var cq   = CompletionQueueSafeHandle.CreateAsync(completionRegistry);
            var call = CreateFakeCall(cq);

            var sendCompletionCallback = new NopSendCompletionCallback();
            var payload    = new byte[payloadSize];
            var writeFlags = default(WriteFlags);

            var stopwatch = Stopwatch.StartNew();

            for (int i = 0; i < iterations; i++)
            {
                call.StartSendMessage(sendCompletionCallback, payload, writeFlags, false);
                var callback = completionRegistry.Extract(completionRegistry.LastRegisteredKey);
                callback.OnComplete(true);
            }
            stopwatch.Stop();
            Console.WriteLine("Elapsed millis: " + stopwatch.ElapsedMilliseconds);

            cq.Dispose();
        }