コード例 #1
0
ファイル: Program.cs プロジェクト: complus206/arch
        static void WorkFunc(object obj)
        {
            int index = (int)obj;
            try
            {
                //TTransport transport = new TSocket(svrAddr, 9090);
                TTransport transport = new TFramedTransport(new TSocket(svrAddr, 9090));
                TProtocol protocol = new TBinaryProtocol(transport);
                //TProtocol protocol = new TCompactProtocol(transport);

                transport.Open();
                Serv.Client client = new Serv.Client(protocol);
                Stopwatch watch = new Stopwatch();

                //Test One by One
                //watch.Start();
                //CreateReserveOneByOne(client);
                //watch.Stop();
                //Console.WriteLine("Create reseve one by one used {0}mss", watch.Elapsed.TotalMilliseconds);

                //Test Batch
                watch = new Stopwatch();
                watch.Start();
                CreateReserveBatch(client);
                watch.Stop();
                Console.WriteLine("Create reseve batch used {0}ms", watch.Elapsed.TotalMilliseconds);

                statResults[index] = watch.Elapsed.TotalMilliseconds;

                transport.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Thread {0} error!", index);
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }
            finally
            {
                manualEvents[index].Set();
                Console.WriteLine("Thread {0} finished!", index);
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: complus206/arch
        static void TestFunc(string svrAddr, int threadCount)
        {
            List<Reserve> list = new List<Reserve>();
            for (int j = 0; j < packageCount; j++)
            {
                Reserve r = CreateTestReserve(j);
                list.Add(r);
            }

            ThriftPool pool = new ThriftPool(new ThriftConfig()
            {
                #region 配置连接池

                Host = svrAddr,
                Port = 9090,
                Timeout = 60,
                MaxActive = 100,
                MaxIdle = 20,
                MinIdle = 5,
                Encode = Encoding.UTF8

                #endregion
            });

            using (FileStream fs = new FileStream(".\\output.log", FileMode.Create, FileAccess.Write))
            {
                PerformanceTestHelper helper = new PerformanceTestHelper((index) =>
                {
                    TTransport transport = pool.BorrowInstance();
                    //TTransport transport = new TFramedTransport(new TSocket(svrAddr, 9090));
                    //TProtocol protocol = new TBinaryProtocol(transport);
                    TProtocol protocol = new TCompactProtocol(transport);
                    //transport.Open();
                    Serv.Client client = new Serv.Client(protocol);

                    client.createBatch(list);

                    pool.ReturnInstance(transport);
                    //transport.Close();

                }, threadCount, 1000, true, fs);
                helper.Run();
            }
        }