Esempio n. 1
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();
        }
Esempio n. 2
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);
        }
Esempio n. 3
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();
        }
Esempio n. 4
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();
        }