Beispiel #1
0
 public void Initialize()
 {
     _theServer = new IrisServer();
     _theServer.Start(56666);
     _theClientConfig = new IrisClientConfig()
     {
         Hostname = "127.0.0.1", Port = 56666
     };
 }
Beispiel #2
0
        private static async void PerfTest()
        {
            channel = "perf";

            await TaskEx.Delay(1000); // Delay for the server to spawn.

            IrisClientConfig config = new IrisClientConfig
            {
                Hostname = "127.0.0.1",
                Port     = 22000,
            };

            actorNode = new IrisClientNode();
            actorNode.Connect(config);
            Console.WriteLine("Actor node connected");

            messagesCount = 20000;
            start         = null;

            receivedMessagesCount = 0;
            Task <IDisposableSubscription> asyncSubscription = null;

            asyncSubscription = actorNode.Subscribe(channel, (c, h) =>
            {
                if (!h.Unsubscribing)
                {
                    var rmc = Interlocked.Increment(ref receivedMessagesCount);

                    if (messagesCount > 10 && rmc % (messagesCount / 10) == 0)
                    {
                        Console.WriteLine($"Received: {c} ({rmc * 100.0 / messagesCount}%)");
                    }

                    if (rmc == messagesCount)
                    {
                        var end = DateTime.Now;
                        var sub = asyncSubscription.Result; // Brutal!
                        sub.Dispose();

                        Task.Factory.StartNew(async() =>
                        {
                            await actorNode.Publish(channel, new Test());
                            actorNode.Dispose();
                        });

                        PerfAnalysis(messagesCount, start.Value, end);
                        actorNode.Dispose();
                    }
                }
            });

            IDisposableSubscription subscription = await asyncSubscription;

            Task[] publishTasks = new Task[messagesCount];

            object bigload = new byte[1000000];

            start = DateTime.Now;

            Console.WriteLine($"Started sending {messagesCount} messages");

            for (int i = 0; i < messagesCount; i++)
            {
                var message = $"message#{i + 1}";
                var task    = actorNode.Publish(channel, new Test {
                    Message = message, Data = bigload
                });
                publishTasks[i] = task;
            }

            await TaskEx.WhenAll(publishTasks);

            Console.WriteLine($"Sent {messagesCount} messages");
        }