Ejemplo n.º 1
0
 public PerfMon(string name, JobSerializer serializer)
 {
     this.name       = name;
     this.serializer = serializer;
     last            = DateTime.Now;
 }
Ejemplo n.º 2
0
        static async Task MainAsync()
        {
            try
            {
                Console.WriteLine("Hello World!");

                int SERIALIZER_COUNT          = 4;
                int GAME_COUNT_PER_SERIALIZER = 1;
                int USER_COUNT_PER_GAME       = 150;

                List <JobSerializer> serializers = new List <JobSerializer>();

                List <PerfMon> perfMons = new List <PerfMon>();
                List <Game>    games    = new List <Game>();

                for (int i = 0; i < SERIALIZER_COUNT; ++i)
                {
                    var serializer = new JobSerializer();
                    serializers.Add(serializer);

                    var perfMon = new PerfMon($"s{i}", serializer);
                    perfMon.Start();
                    perfMons.Add(perfMon);

                    for (int j = 0; j < GAME_COUNT_PER_SERIALIZER; ++j)
                    {
                        var  num  = i;
                        Game game = new Game(serializer, num, USER_COUNT_PER_GAME);
                        game.Init();
                        games.Add(game);
                    }

                    serializer.Start();
                }

                bool perfLogRun  = true;
                var  taskPerfLog = Task.Run(() =>
                {
                    DateTime serverUpTime = DateTime.Now;

                    while (perfLogRun)
                    {
                        var current = DateTime.Now;
                        var diff    = current - serverUpTime;

                        Console.WriteLine("=======================================================");
                        Console.WriteLine($"up:{serverUpTime}, current:{current}, diff:{diff}");
                        Console.WriteLine($"pc: {PC.workingPcCount}, npc: {NPC.workingNpcCount}");
                        Console.WriteLine($"buffer: {NetBuffer.AllocStateString()}");
                        Console.WriteLine("=======================================================");
                        foreach (var pm in perfMons)
                        {
                            Console.WriteLine(pm.PerfString());
                        }
                        Console.WriteLine("=======================================================");
                        Console.WriteLine();

                        if (perfLogRun)
                        {
                            System.Threading.Thread.Sleep(3000);
                        }
                    }
                });

                for (;;)
                {
                    var key     = Console.ReadKey();
                    var keyChar = key.KeyChar;
                    if (keyChar == 'q')
                    {
                        foreach (var s in serializers)
                        {
                            s.Stop();
                        }
                        break;
                    }
                    else if (keyChar == 'g')
                    {
                        Console.WriteLine("garbage collect start");
                        GC.Collect();
                        Console.WriteLine("garbage collect start");
                    }
                }

                Console.WriteLine("wait for jobSerializer end...");

                foreach (var s in serializers)
                {
                    await s.Completion;
                }

                perfLogRun = false;
                await taskPerfLog;
            }
            finally
            {
                Console.WriteLine("bye!");
            }
        }
Ejemplo n.º 3
0
 public Game(JobSerializer serializer, int num, int userCount)
 {
     this.serializer = serializer;
     this.USER_COUNT = userCount;
     this.number     = num;
 }