Beispiel #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();
        }
        public void CreateAsyncAndShutdown()
        {
            var env = GrpcEnvironment.AddRef();
            var cq  = CompletionQueueSafeHandle.CreateAsync(new CompletionRegistry(env, () => BatchContextSafeHandle.Create(), () => RequestCallContextSafeHandle.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);
        }
        private void RunBody()
        {
            var completionRegistry = new CompletionRegistry(Environment, () => Environment.BatchContextPool.Lease(), () => throw new NotImplementedException());
            var cq   = CompletionQueueSafeHandle.CreateAsync(completionRegistry);
            var call = CreateFakeCall(cq);

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

            for (int i = 0; i < Iterations; i++)
            {
                call.StartSendMessage(sendCompletionCallback, payload, writeFlags, false);
                var callback = completionRegistry.Extract(completionRegistry.LastRegisteredKey);
                callback.OnComplete(true);
            }
            cq.Dispose();
        }
Beispiel #4
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);
        }
Beispiel #5
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();
        }
        private void RunBody()
        {
            var completionRegistry = new CompletionRegistry(Environment, () => Environment.BatchContextPool.Lease(), () => throw new NotImplementedException());
            var cq   = CompletionQueueSafeHandle.CreateAsync(completionRegistry);
            var call = CreateFakeCall(cq);

            var sendCompletionCallback = new NopSendCompletionCallback();
            var sliceBuffer            = SliceBufferSafeHandle.Create();
            var writeFlags             = default(WriteFlags);

            for (int i = 0; i < Iterations; i++)
            {
                // SendMessage steals the slices from the slice buffer, so we need to repopulate in each iteration.
                sliceBuffer.Reset();
                sliceBuffer.GetSpan(PayloadSize);
                sliceBuffer.Advance(PayloadSize);

                call.StartSendMessage(sendCompletionCallback, sliceBuffer, writeFlags, false);
                var callback = completionRegistry.Extract(completionRegistry.LastRegisteredKey);
                callback.OnComplete(true);
            }
            sliceBuffer.Dispose();
            cq.Dispose();
        }