コード例 #1
0
        public async Task <IActionResult> Get()
        {
            var request = new BigDataRequest()
            {
                Input = "1"
            };
            var result = await _consumerHandler.ExecuteRequest <BigDataRequest, BigDataResponse>(request);

            return(Ok(JsonConvert.SerializeObject(result)));
        }
コード例 #2
0
        private async void gRPCBigDataBothStreamTry()
        {
            Stopwatch sw1 = new Stopwatch();
            Stopwatch sw2 = new Stopwatch();

            sw1.Start();

            try
            {
                AppendText("starting Both Steam Calling...");
                var channel = GrpcChannel.ForAddress(DefaultChannelAddress);
                var client  = new StreamShoper.StreamShoperClient(channel);

                var cancelSource = new CancellationTokenSource();
                var token        = cancelSource.Token;

                var call = client.SendingBigDataPackage(null, null, token);
                AppendText("Start to send data...");


                sw2.Start();

                AppendText($"Parameters: Send Times is {SendTimes}, Package size is {packageSize}M");

                for (int i = SendTimes; i >= 0; i--)
                {
                    AppendText($"#From Client# the index is {i}");
                    var request = new BigDataRequest {
                        DataType = $"index{i}"
                    };

                    var strTmp = new string('A', (int)(1024 * 1024 * packageSize));

                    var size = ((double)Encoding.UTF8.GetByteCount(strTmp) / (1024 * 1024)).ToString("f3");
                    AppendText($"Per item size is {size}M");

                    var times = 1; // total ~1M
                    while (times > 0)
                    {
                        request.Content.Add(strTmp);
                        times--;
                    }

                    await call.RequestStream.WriteAsync(request);

                    await call.ResponseStream.MoveNext(token);

                    var response = call.ResponseStream.Current;
                    AppendText(response.Message);

                    //AppendText("Waiting 2 seconds...");
                    //await Task.Delay(2000);

                    //await Task.Delay(100);
                }
                AppendText("Starting cancelling...");
                cancelSource.Cancel();
                AppendText("Cancelled");
                sw2.Stop();
            }
            catch (Exception ex)
            {
                AppendText(ex.Message);
                AppendText("Exception, Cancelling...");
            }

            sw1.Stop();

            AppendText($"Sending data time cost:{sw2.Elapsed.TotalSeconds}");
            AppendText($"Total time cost:{sw1.Elapsed.TotalSeconds}");
        }