public RpcMethodAttribute(string id, Type type = null, RpcType rpcType = RpcType.User)
 {
     if (string.IsNullOrEmpty(id))
     {
         throw new ArgumentNullException(nameof(id));
     }
     Id      = id;
     RpcType = rpcType;
 }
Example #2
0
        public ClientRunnerImpl(List <Channel> channels, ClientType clientType, RpcType rpcType, int outstandingRpcsPerChannel, LoadParams loadParams, PayloadConfig payloadConfig, HistogramParams histogramParams)
        {
            GrpcPreconditions.CheckArgument(outstandingRpcsPerChannel > 0, "outstandingRpcsPerChannel");
            this.channels      = new List <Channel>(channels);
            this.clientType    = clientType;
            this.rpcType       = rpcType;
            this.payloadConfig = payloadConfig;
            this.histogram     = new Histogram(histogramParams.Resolution, histogramParams.MaxPossible);

            this.runnerTasks = new List <Task>();
            foreach (var channel in this.channels)
            {
                for (int i = 0; i < outstandingRpcsPerChannel; i++)
                {
                    var timer      = CreateTimer(loadParams, 1.0 / this.channels.Count / outstandingRpcsPerChannel);
                    var threadBody = GetThreadBody(channel, timer);
                    this.runnerTasks.Add(Task.Factory.StartNew(threadBody, TaskCreationOptions.LongRunning));
                }
            }
        }
        public ClientRunnerImpl(List <Channel> channels, ClientType clientType, RpcType rpcType, int outstandingRpcsPerChannel, LoadParams loadParams, PayloadConfig payloadConfig, HistogramParams histogramParams)
        {
            GrpcPreconditions.CheckArgument(outstandingRpcsPerChannel > 0, "outstandingRpcsPerChannel");
            GrpcPreconditions.CheckNotNull(histogramParams, "histogramParams");
            this.channels      = new List <Channel>(channels);
            this.clientType    = clientType;
            this.rpcType       = rpcType;
            this.payloadConfig = payloadConfig;
            this.histogram     = new Histogram(histogramParams.Resolution, histogramParams.MaxPossible);

            this.runnerTasks = new List <Task>();
            foreach (var channel in this.channels)
            {
                for (int i = 0; i < outstandingRpcsPerChannel; i++)
                {
                    var timer = CreateTimer(loadParams, 1.0 / this.channels.Count / outstandingRpcsPerChannel);
                    this.runnerTasks.Add(RunClientAsync(channel, timer));
                }
            }
        }
        public ClientRunnerImpl(List <Channel> channels, ClientType clientType, RpcType rpcType, int outstandingRpcsPerChannel, LoadParams loadParams, PayloadConfig payloadConfig, HistogramParams histogramParams, Func <BasicProfiler> profilerFactory)
        {
            GrpcPreconditions.CheckArgument(outstandingRpcsPerChannel > 0, "outstandingRpcsPerChannel");
            GrpcPreconditions.CheckNotNull(histogramParams, "histogramParams");
            this.channels                = new List <Channel>(channels);
            this.clientType              = clientType;
            this.rpcType                 = rpcType;
            this.payloadConfig           = payloadConfig;
            this.cachedByteBufferRequest = new Lazy <byte[]>(() => new byte[payloadConfig.BytebufParams.ReqSize]);
            this.threadLocalHistogram    = new ThreadLocal <Histogram>(() => new Histogram(histogramParams.Resolution, histogramParams.MaxPossible), true);

            this.runnerTasks = new List <Task>();
            foreach (var channel in this.channels)
            {
                for (int i = 0; i < outstandingRpcsPerChannel; i++)
                {
                    var timer            = CreateTimer(loadParams, 1.0 / this.channels.Count / outstandingRpcsPerChannel);
                    var optionalProfiler = profilerFactory();
                    this.runnerTasks.Add(RunClientAsync(channel, timer, optionalProfiler));
                }
            }
        }
        public ClientRunner(List <GrpcChannel> channels, ClientType clientType, RpcType rpcType, int outstandingRpcsPerChannel, LoadParams loadParams, PayloadConfig payloadConfig, HistogramParams histogramParams, ILogger logger)
        {
            GrpcPreconditions.CheckArgument(outstandingRpcsPerChannel > 0, nameof(outstandingRpcsPerChannel));
            GrpcPreconditions.CheckNotNull(histogramParams, nameof(histogramParams));
            GrpcPreconditions.CheckNotNull(loadParams, nameof(loadParams));
            GrpcPreconditions.CheckNotNull(payloadConfig, nameof(payloadConfig));
            _channels                = new List <GrpcChannel>(channels);
            _clientType              = clientType;
            _rpcType                 = rpcType;
            _payloadConfig           = payloadConfig;
            _logger                  = logger;
            _cachedByteBufferRequest = new Lazy <byte[]>(() => new byte[payloadConfig.BytebufParams.ReqSize]);
            _threadLocalHistogram    = new ThreadLocal <Histogram>(() => new Histogram(histogramParams.Resolution, histogramParams.MaxPossible), true);

            _runnerTasks = new List <Task>();
            foreach (var channel in _channels)
            {
                for (var i = 0; i < outstandingRpcsPerChannel; i++)
                {
                    var timer = CreateTimer(loadParams, 1.0 / _channels.Count / outstandingRpcsPerChannel);
                    _runnerTasks.Add(RunClientAsync(channel, timer));
                }
            }
        }
Example #6
0
        private async Task RunSingleRpcAsync(TestService.TestServiceClient client, CancellationToken cancellationToken, RpcType rpcType)
        {
            long rpcId = statsWatcher.RpcIdGenerator.Increment();

            try
            {
                // metadata to send with the RPC
                var headers = new Metadata();
                if (metadata.ContainsKey(rpcType))
                {
                    headers = metadata[rpcType];
                    if (headers.Count > 0)
                    {
                        var printableHeaders = "[" + string.Join(", ", headers) + "]";
                    }
                }

                if (rpcType == RpcType.UnaryCall)
                {
                    var call = client.UnaryCallAsync(new SimpleRequest(),
                                                     new CallOptions(headers: headers, cancellationToken: cancellationToken, deadline: DateTime.UtcNow.AddSeconds(options.RpcTimeoutSec)));

                    var response = await call;
                    var hostname = (await call.ResponseHeadersAsync).GetValue("hostname") ?? response.Hostname;
                    statsWatcher.OnRpcComplete(rpcId, rpcType, hostname);
                    if (options.PrintResponse)
                    {
                        Console.WriteLine($"Got response {response}");
                    }
                }
                else if (rpcType == RpcType.EmptyCall)
                {
                    var call = client.EmptyCallAsync(new Empty(),
                                                     new CallOptions(headers: headers, cancellationToken: cancellationToken, deadline: DateTime.UtcNow.AddSeconds(options.RpcTimeoutSec)));

                    var response = await call;
                    var hostname = (await call.ResponseHeadersAsync).GetValue("hostname");
                    statsWatcher.OnRpcComplete(rpcId, rpcType, hostname);
                    if (options.PrintResponse)
                    {
                        Console.WriteLine($"Got response {response}");
                    }
                }
                else
                {
                    throw new InvalidOperationException($"Unsupported RPC type ${rpcType}");
                }
            }
            catch (RpcException ex)
            {
                statsWatcher.OnRpcComplete(rpcId, rpcType, null);
                if (options.PrintResponse)
                {
                    Console.WriteLine($"RPC {rpcId} failed: {ex}");
                }
            }
        }
        public ClientRunnerImpl(List<Channel> channels, ClientType clientType, RpcType rpcType, int outstandingRpcsPerChannel, LoadParams loadParams, PayloadConfig payloadConfig, HistogramParams histogramParams, Func<BasicProfiler> profilerFactory)
        {
            GrpcPreconditions.CheckArgument(outstandingRpcsPerChannel > 0, "outstandingRpcsPerChannel");
            GrpcPreconditions.CheckNotNull(histogramParams, "histogramParams");
            this.channels = new List<Channel>(channels);
            this.clientType = clientType;
            this.rpcType = rpcType;
            this.payloadConfig = payloadConfig;
            this.histogram = new Histogram(histogramParams.Resolution, histogramParams.MaxPossible);

            this.runnerTasks = new List<Task>();
            foreach (var channel in this.channels)
            {
                for (int i = 0; i < outstandingRpcsPerChannel; i++)
                {
                    var timer = CreateTimer(loadParams, 1.0 / this.channels.Count / outstandingRpcsPerChannel);
                    var optionalProfiler = profilerFactory();
                    this.runnerTasks.Add(RunClientAsync(channel, timer, optionalProfiler));
                }
            }
        }
 public RpcResponseAttribute(string id, Type type = null, RpcType rpcType = RpcType.User)
     : base(id, type, rpcType)
 {
 }
 public static bool IsFireAndForget(this RpcType rpcType)
 {
     return(rpcType == RpcType.FireAndForget || rpcType == RpcType.Impulse);
 }
Example #10
0
        public ClientRunnerImpl(List<Channel> channels, ClientType clientType, RpcType rpcType, int outstandingRpcsPerChannel, LoadParams loadParams, PayloadConfig payloadConfig, HistogramParams histogramParams)
        {
            GrpcPreconditions.CheckArgument(outstandingRpcsPerChannel > 0, "outstandingRpcsPerChannel");
            this.channels = new List<Channel>(channels);
            this.clientType = clientType;
            this.rpcType = rpcType;
            this.payloadConfig = payloadConfig;
            this.histogram = new Histogram(histogramParams.Resolution, histogramParams.MaxPossible);

            this.runnerTasks = new List<Task>();
            foreach (var channel in this.channels)
            {
                for (int i = 0; i < outstandingRpcsPerChannel; i++)
                {
                    var timer = CreateTimer(loadParams, 1.0 / this.channels.Count / outstandingRpcsPerChannel);
                    var threadBody = GetThreadBody(channel, timer);
                    this.runnerTasks.Add(Task.Factory.StartNew(threadBody, TaskCreationOptions.LongRunning));
                }
            }
        }
Example #11
0
        private RpcArgument CreateRpcArgument(ITransportChannel channel, IRpcObjectRepository localRepository, object argument, Type argumentType)
        {
            string  typeid = null;
            RpcType type   = RpcType.Proxy;

            RpcArgument[] arrayElements = null;
            if (argument == null ||
                argument is IConvertible)
            {
                type = RpcType.Builtin;
            }
            else if (argument is Array array)
            {
                if ((argument.GetType().GetElementType()?.IsPrimitive ?? false) ||
                    argument.GetType().GetElementType() == typeof(string))
                {
                    type = RpcType.Builtin;
                }
                else
                {
                    type = RpcType.ObjectArray;
                    // make sure we use the correct interface definition as base type (we might get a specific array here)
                    var arrayTemplate = Array.CreateInstance(argumentType.GetElementType(), 0);
                    typeid   = localRepository.CreateTypeId(arrayTemplate);
                    argument = array.Length;
                    var elementType = argumentType.GetElementType();
                    arrayElements = new RpcArgument[array.Length];
                    for (int i = 0; i < array.Length; i++)
                    {
                        arrayElements[i] = CreateRpcArgument(channel, localRepository, array.GetValue(i), elementType);
                    }
                }
            }
            else if (argumentType != typeof(object) &&
                     !argumentType.IsSubclassOf(typeof(Delegate)) &&
                     (argumentType.GetCustomAttribute <SerializableAttribute>() != null ||
                      (argument.GetType().GetCustomAttribute <SerializableAttribute>() != null)))
            {
                type   = RpcType.Serialized;
                typeid = localRepository.CreateTypeId(argument);
            }
            else
            {
                typeid = localRepository.CreateTypeId(argument);

                if (argument is IRpcObjectProxy proxy)
                {
                    /*var instance = localRepository.GetInstance(proxy.LocalInstanceId);
                     * if (instance != null) // todo this check is not necessary
                     * {
                     *  argument = proxy.LocalInstanceId;
                     * }*/
                    argument = proxy.RemoteInstanceId;
                }
                else
                {
                    argument = localRepository.AddInstance(argumentType, argument, channel).InstanceId;
                }
            }

            return(new RpcArgument
            {
                Type = type,
                Value = argument,
                TypeId = typeid,
                ArrayElements = arrayElements
            });
        }
Example #12
0
 public ServiceOperation(RpcType eType = RpcType.TwoWay)
 {
     Type = eType;
 }