コード例 #1
0
ファイル: ServerSafeHandle.cs プロジェクト: wangcy6/storm_app
 public void ShutdownAndNotify(BatchCompletionDelegate callback, CompletionQueueSafeHandle completionQueue)
 {
     using (completionQueue.NewScope())
     {
         var ctx = BatchContextSafeHandle.Create();
         // TODO(jtattermusch): delegate allocation by caller can be avoided by utilizing the "state" object,
         // but server shutdown isn't worth optimizing right now.
         completionQueue.CompletionRegistry.RegisterBatchCompletion(ctx, callback, null);
         Native.grpcsharp_server_shutdown_and_notify_callback(this, completionQueue, ctx);
     }
 }
コード例 #2
0
        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();
        }
コード例 #3
0
        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();
        }
コード例 #4
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();
        }
コード例 #5
0
ファイル: GrpcEnvironment.cs プロジェクト: franghie/grpc
 /// <summary>
 /// Creates gRPC environment.
 /// </summary>
 private GrpcEnvironment()
 {
     GrpcNativeInit();
     batchContextPool       = new DefaultObjectPool <BatchContextSafeHandle>(() => BatchContextSafeHandle.Create(this.batchContextPool), batchContextPoolSharedCapacity, batchContextPoolThreadLocalCapacity);
     requestCallContextPool = new DefaultObjectPool <RequestCallContextSafeHandle>(() => RequestCallContextSafeHandle.Create(this.requestCallContextPool), requestCallContextPoolSharedCapacity, requestCallContextPoolThreadLocalCapacity);
     threadPool             = new GrpcThreadPool(this, GetThreadPoolSizeOrDefault(), GetCompletionQueueCountOrDefault(), inlineHandlers);
     threadPool.Start();
 }
コード例 #6
0
        public void CreateAsyncAndShutdown()
        {
            var env = GrpcEnvironment.AddRef();
            var cq  = CompletionQueueSafeHandle.CreateAsync(new CompletionRegistry(env, () => BatchContextSafeHandle.Create()));

            cq.Shutdown();
            var ev = cq.Next();

            cq.Dispose();
            GrpcEnvironment.ReleaseAsync().Wait();
            Assert.AreEqual(CompletionQueueEvent.CompletionType.Shutdown, ev.type);
            Assert.AreNotEqual(IntPtr.Zero, ev.success);
            Assert.AreEqual(IntPtr.Zero, ev.tag);
        }
コード例 #7
0
 public void RegisterExtract()
 {
     RunConcurrent(() => {
         CompletionRegistry sharedRegistry = UseSharedRegistry ? new CompletionRegistry(Environment, () => BatchContextSafeHandle.Create(), () => RequestCallContextSafeHandle.Create()) : null;
         RunBody(sharedRegistry);
     });
 }
コード例 #8
0
        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
        }