예제 #1
0
        public override Task <Stat> LoadJobConfig(CellJobConfig config, ServerCallContext context)
        {
            try
            {
                var jobConfig = new JobConfig
                {
                    Connections           = config.Connections,
                    ConcurrentConnections = config.ConcurrentConnections,
                    // Slaves = config.Slaves,
                    Interval  = config.Interval,
                    Duration  = config.Duration,
                    ServerUrl = config.ServerUrl,
                    Pipeline  = new List <string>(config.Pipeline.Split(';')),
                };

                // TODO: handle exception
                if (_sigWorker == null)
                {
                    _sigWorker = new SigWorker();
                }

                _sigWorker.LoadJobs(jobConfig);
                _sigWorker.UpdateState(Stat.Types.State.ConfigLoaded);
                return(Task.FromResult(new Stat {
                    State = Stat.Types.State.ConfigLoaded
                }));
            }
            catch (Exception ex)
            {
                Util.Log($"Exception: {ex}");
                throw;
            }
        }
예제 #2
0
        private static void ClientsLoadJobConfig(List <RpcService.RpcServiceClient> clients,
                                                 List <string> slaveList, ArgsOption argsOption)
        {
            var connectionCnt        = argsOption.Connections;
            var concurrentConnection = argsOption.ConcurrentConnection;
            var duration             = argsOption.Duration;
            var interval             = argsOption.Interval;
            var pipelineStr          = argsOption.PipeLine;
            var serverUrl            = argsOption.ServerUrl;
            var messageSizeStr       = argsOption.MessageSize;

            var messageSize = ParseMessageSize(messageSizeStr);

            string[] servers     = null;
            int      serverCount = 0;

            if (serverUrl != null)
            {
                servers     = serverUrl.Split(';');
                serverCount = servers.Length;
            }
            var connectionString = argsOption.ConnectionString;

            clients.ForEach(client =>
            {
                var i = clients.IndexOf(client);
                var clientConnections     = Util.SplitNumber(connectionCnt, i, slaveList.Count);
                var concurrentConnections = Util.SplitNumber(concurrentConnection, i, slaveList.Count);
                // modify the illegal case
                if (clientConnections > 0 && concurrentConnections == 0)
                {
                    Util.Log($"Warning: the concurrent connection '{concurrentConnection}' is too small, it is '{slaveList.Count}' at least");
                    concurrentConnections = 1;
                }
                else if (concurrentConnection > connectionCnt)
                {
                    Util.Log($"Warning: the concurrent connection '{concurrentConnection}' is too large, it is '{connectionCnt}' at most");
                    concurrentConnection = connectionCnt;
                }
                var state = new Stat();
                state     = client.CreateWorker(new Empty());

                string server = null;
                if (serverUrl != null)
                {
                    if (bool.Parse(argsOption.SendToFixedClient))
                    {
                        server = serverUrl;
                    }
                    else
                    {
                        server = servers[i % serverCount];
                    }
                }
                else if (connectionString != null)
                {
                    // temporarily borrow the 'server' field to pass connection string,
                    // because I do not want to modify RPC model.
                    server = connectionString;
                }
                var config = new CellJobConfig
                {
                    Connections           = clientConnections,
                    ConcurrentConnections = concurrentConnections,
                    Interval  = interval,
                    Duration  = duration,
                    ServerUrl = server,
                    Pipeline  = pipelineStr,
                };

                Util.Log($"create worker state: {state.State}");
                Util.Log($"client connections: {config.Connections}");
                state = client.LoadJobConfig(config);
                Util.Log($"load job config state: {state.State}");
            });
        }