示例#1
0
 public PearTestRunner()
 {
     protocolWrapper       = null;
     netClients            = null;
     metricManager         = null;
     stopWatch             = null;
     stopMark              = false;
     logFinalMark          = false;
     timerForLogging       = null;
     timerForIntervalRelay = null;
     mutex     = new Mutex();
     sendQueue = new ConcurrentQueue <int>();
 }
示例#2
0
        public bool Init(string configFileName)
        {
            if (!ConfigManager.Instance.Init(configFileName))
            {
                Logger.Instance.LogError("读取配置文件失败");
                return(false);
            }
            Logger.Instance.LogTrace("配置文件读取成功");
            protocolWrapper = ProtocolWrapperFactory.GetProtocolWrapper("");
            metricManager   = new MetricManager();
            if (!metricManager.Init(ConfigManager.Instance.SendPoolSize))
            {
                Logger.Instance.LogError("性能计数器初始化失败");
                return(false);
            }
            Logger.Instance.LogTrace("性能计数器初始化成功");
            netClients = new NetClients(ConfigManager.Instance.Protocol, ConfigManager.Instance.ClientCount,
                                        ConfigManager.Instance.ThreadsPerClient, ConfigManager.Instance.BufferSize);
            netClients.OnSend    += this.OnSend;
            netClients.OnSend    += metricManager.OnSend;
            netClients.OnReceive += this.OnReceive;
            netClients.OnReceive += metricManager.OnReceive;
            if (!netClients.Init(ConfigManager.Instance.IP, ConfigManager.Instance.Port))
            {
                Logger.Instance.LogError("客户端连接初始化失败");
                return(false);
            }
            Logger.Instance.LogTrace("客户端连接初始化成功");
            stopWatch = new Stopwatch();

            Console.WriteLine($"压测目标: [{ConfigManager.Instance.Protocol.ToUpper()}] {ConfigManager.Instance.Target.ToString()}");
            Console.WriteLine($"客户端连接数: {ConfigManager.Instance.ClientCount}, 发送池大小: {ConfigManager.Instance.SendPoolSize}");
            if (ConfigManager.Instance.ControlMode == "count")
            {
                Console.WriteLine($"预计发包数量: {ConfigManager.Instance.ControlParam}");
            }
            else if (ConfigManager.Instance.ControlMode == "time")
            {
                Console.WriteLine($"预计发包时间: {ConfigManager.Instance.ControlParam / 1000}s");
            }
            else if (ConfigManager.Instance.ControlMode == "manual")
            {
                Console.WriteLine("手动停止发包(按任意键退出程序)");
            }
            else
            {
                Console.WriteLine($"未知控制模式: {ConfigManager.Instance.ControlMode}");
            }
            if (ConfigManager.Instance.DataProtocol == "raw")
            {
                Console.WriteLine($"数据协议: 普通回显服务");
            }
            else if (ConfigManager.Instance.DataProtocol == "fakes5")
            {
                Console.WriteLine($"数据协议: 经典LSP协议/回显, 真实目标: {ConfigManager.Instance.TargetAcc}");
            }
            else if (ConfigManager.Instance.DataProtocol == "fakes5echo")
            {
                Console.WriteLine($"数据协议: 经典LspUdping, 真实目标: 海外S5节点");
            }
            else
            {
                Console.WriteLine($"数据协议: 未知, 不可思议的事情发生了");
            }
            if (ConfigManager.Instance.RelayMode == "interval")
            {
                Console.WriteLine($"发包模式: 连续发送, 间隔时间: {ConfigManager.Instance.RelayInterval}ms");
            }
            else if (ConfigManager.Instance.RelayMode == "onsend")
            {
                Console.WriteLine($"发包模式: 固定速度发包, 发包速度: {ConfigManager.Instance.RelayMaxPps}pps");
            }
            else if (ConfigManager.Instance.RelayMode == "onrecv")
            {
                Console.WriteLine($"发包模式: 接力发送, 热身包量: {ConfigManager.Instance.WarmupCount}, 热身包间隔: {ConfigManager.Instance.WarmupInterval}ms");
            }
            else
            {
                Console.WriteLine($"未知发包模式: {ConfigManager.Instance.RelayMode}");
            }
            Console.WriteLine("");

            Logger.Instance.LogInfo("压测程序初始化成功\r\n");
            return(true);
        }