Exemplo n.º 1
0
        private void btnReactor_Click(object sender, EventArgs e)
        {
            using (var client1 = new JokeContractClient(cbo.Text))
                using (var client2 = new JokeContractClient(cbo.Text))
                {
                    var result = "";

                    var reactor = new CallReactor(false,
                                                  new Call(client1.Async_Echo("One."), (r, call) => result   += call.CallSlot.GetValue <string>()),
                                                  new Call(client2.Async_Echo("Two."), (r, call) => result   += call.CallSlot.GetValue <string>()),
                                                  new Call(client1.Async_Echo("Three."), (r, call) => result += call.CallSlot.GetValue <string>())
                                                  );

                    reactor.Wait();

                    MessageBox.Show(result);
                }
        }
Exemplo n.º 2
0
        public static void TestContractB_4_AsyncReactor(string CONF_SRC)
        {
            var conf = LaconicConfiguration.CreateFromString(CONF_SRC);

            using (var app = new ServiceBaseApplication(null, conf.Root))
            {
                var cl = new TestContractBClient(App.ConfigRoot.AttrByName("cs").Value);

                var reactor = new CallReactor(
                    new Call(cl.Async_GetName(), (r, c) => Assert.AreEqual("Felix", c.CallSlot.GetValue <string>())),
                    new Call(cl.Async_GetName(23), (r, c) => Assert.AreEqual("Felix23", c.CallSlot.GetValue <string>())),
                    new Call(cl.Async_GetName(42), (r, c) => Assert.AreEqual("Felix42", c.CallSlot.GetValue <string>())),
                    new Call(cl.Async_GetName(2, DateTime.Now), (r, c) => Assert.IsTrue(c.CallSlot.GetValue <string>().StartsWith("Felix2")))
                    );

                reactor.Wait();

                dumpBindingTransports(cl.Binding);
                Assert.IsTrue(reactor.Finished);
            }
        }
Exemplo n.º 3
0
        private void btnSimpleWork_Click(object sender, EventArgs e)
        {
            warmup();
            var marshal = chkArgsMarshalling.Checked;

            Text        = "Working...";
            tbNote.Text = "Started...";
            var w = Stopwatch.StartNew();

            var node = cbo.Text;
            //var totalCalls = tbCallsPerReactor.Text.AsInt();

            var rcount = tbReactors.Text.AsInt(10);
            var prc    = tbCallsPerReactor.Text.AsInt();//totalCalls / rcount;
            var auth   = new AuthenticationHeader(new IDPasswordCredentials(tbID.Text, tbPwd.Text));

            var totalCalls = rcount * prc;

            var calls   = new ConcurrentQueue <Call>();
            var derrors = new ConcurrentQueue <string>();
            var tasks   = new List <Task>();

            for (var i = 0; i < rcount; i++)
            {
                tasks.Add(Task.Factory.StartNew((idx) =>
                {
                    var lcl = new JokeContractClient(node);
                    lcl.DispatchTimeoutMs = 5 * 1000;
                    lcl.TimeoutMs         = 40 * 1000;
                    lcl.ReserveTransport  = true;

                    for (var j = 0; j < prc; j++)
                    {
                        try { calls.Enqueue(new Call(marshal ? lcl.Async_SimpleWorkMar("Call number {0} ".Args(j), j, i, true, 123.12)
                                                                      : lcl.Async_SimpleWorkAny("Call number {0} ".Args(j), j, i, true, 123.12))); }
                        catch (Exception err)
                        {
                            derrors.Enqueue("{0}: {1}\r\n".Args(j, err.ToMessageWithType()));
                        }
                    }        //for

                    lcl.Dispose();
                }, i, TaskCreationOptions.LongRunning));
            }

            Task.WaitAll(tasks.ToArray());

            string estr = null;

            while (derrors.TryDequeue(out estr))
            {
                tbNote.Text += estr;
            }


            var reactor = new CallReactor(calls);

            var callsPlaced = w.ElapsedMilliseconds;

            reactor.Wait();


            var stats = new ConcurrentDictionary <CallStatus, int>();

            foreach (var call in reactor.Calls)
            {
                if (call.CallSlot.CallStatus == CallStatus.ResponseError)
                {
                    var msg = call.CallSlot.ResponseMsg;
                    Text = msg.ExceptionData.Message;
                }
                stats.AddOrUpdate(call.CallSlot.CallStatus, 1, (_, k) => k + 1);
            }

            var sb = new StringBuilder();

            foreach (var k in stats.Keys)
            {
                sb.AppendLine("{0} = {1} times".Args(k, stats[k]));
            }

            tbNote.Text += sb.ToString();

            var allFinished = w.ElapsedMilliseconds;

            Text = "Placed {0:n2} calls in {1:n2} ms, then waited {2:n2} ms for finish, total time {3:n2} ms @ {4:n2} calls/sec "
                   .Args
                   (
                totalCalls,
                callsPlaced,
                allFinished - callsPlaced,
                allFinished,
                totalCalls / (allFinished / 1000d)
                   );
        }
Exemplo n.º 4
0
        private void btnManyDBWorks_Click(object sender, EventArgs e)
        {
            warmup();
            var rCount   = tbRecCount.Text.AsInt();
            var waitFrom = tbWaitFrom.Text.AsInt();
            var waitTo   = tbWaitTo.Text.AsInt();

            Text        = "Working...";
            tbNote.Text = "Started...";
            var w = Stopwatch.StartNew();

            var client = new JokeContractClient(cbo.Text);

            client.DispatchTimeoutMs = 5 * 1000;
            client.TimeoutMs         = 40 * 1000;

            var totalCalls = tbCallsPerReactor.Text.AsInt();


            var calls   = new ConcurrentQueue <Call>();
            var derrors = new ConcurrentQueue <string>();

            System.Threading.Tasks.Parallel.For(0, totalCalls,
                                                (i) =>
            {
                try
                {
                    calls.Enqueue(new Call(client.Async_DBWork(i.ToString(), rCount,
                                                               waitFrom > 0 ? ExternalRandomGenerator.Instance.NextScaledRandomInteger(waitFrom, waitTo) : 0)));
                    //ExternalRandomGenerator.Instance.NextScaledRandomInteger(1,100),
                    //ExternalRandomGenerator.Instance.NextScaledRandomInteger(0,50))) );
                }
                catch (Exception err)
                {
                    derrors.Enqueue("{0}: {1}\r\n".Args(1, err.ToMessageWithType()));
                }
            });



            string estr = null;

            while (derrors.TryDequeue(out estr))
            {
                tbNote.Text += estr;
            }


            var reactor = new CallReactor(calls);

            var callsPlaced = w.ElapsedMilliseconds;

            reactor.Wait();


            var stats = new ConcurrentDictionary <CallStatus, int>();

            foreach (var call in reactor.Calls)
            {
                if (call.CallSlot.CallStatus == CallStatus.ResponseError)
                {
                    var msg = call.CallSlot.ResponseMsg;
                    Text = msg.ExceptionData.Message;
                }
                stats.AddOrUpdate(call.CallSlot.CallStatus, 1, (_, k) => k + 1);
            }

            var sb = new StringBuilder();

            foreach (var k in stats.Keys)
            {
                sb.AppendLine("{0} = {1} times".Args(k, stats[k]));
            }

            tbNote.Text += sb.ToString();

            var allFinished = w.ElapsedMilliseconds;

            Text = "Placed {0} DB calls in {1} ms, then waited {2} ms for finish, total time {3} ms @ {4} calls/sec "
                   .Args
                   (
                totalCalls,
                callsPlaced,
                allFinished - callsPlaced,
                allFinished,
                (1000 * totalCalls) / allFinished
                   );


            if (chkAutoDispatch.Checked)
            {
                tmrAuto.Interval = 1000 + ExternalRandomGenerator.Instance.NextScaledRandomInteger(100, 10000);
                tmrAuto.Enabled  = true;
            }
        }
Exemplo n.º 5
0
        private void btnParallelDispatch_Click(object sender, EventArgs e)
        {
            warmup();
            var unsecure    = chkUnsecureEcho.Checked;
            var argsMarshal = chkArgsMarshalling.Checked;

            Text        = "Working...";
            tbNote.Text = "Started...";
            var w = Stopwatch.StartNew();

            var client = new JokeContractClient(cbo.Text);

            client.DispatchTimeoutMs = 5 * 1000;
            client.TimeoutMs         = 40 * 1000;
            if (!unsecure && chkImpersonate.Checked)
            {
                client.Headers.Add(new AuthenticationHeader(new IDPasswordCredentials(tbID.Text, tbPwd.Text)));
            }

            var totalCalls = tbCallsPerReactor.Text.AsInt();


            var calls   = new ConcurrentQueue <Call>();
            var derrors = new ConcurrentQueue <string>();

            System.Threading.Tasks.Parallel.For(0, totalCalls,
                                                (i) =>
            {
                try
                {
                    calls.Enqueue(new Call(
                                      argsMarshal ?
                                      client.Async_UnsecEchoMar("Call number {0} ".Args(i))
                                         :
                                      (unsecure ? client.Async_UnsecureEcho("Call number {0} ".Args(i))
                                                  : client.Async_Echo("Call number {0} ".Args(i)))));
                }
                catch (Exception err)
                {
                    derrors.Enqueue("{0}: {1}\r\n".Args(1, err.ToMessageWithType()));
                }
            });



            string estr = null;

            while (derrors.TryDequeue(out estr))
            {
                tbNote.Text += estr;
            }


            var reactor = new CallReactor(calls);

            var callsPlaced = w.ElapsedMilliseconds;

            reactor.Wait();


            var stats = new ConcurrentDictionary <CallStatus, int>();

            foreach (var call in reactor.Calls)
            {
                if (call.CallSlot.CallStatus == CallStatus.ResponseError)
                {
                    var msg = call.CallSlot.ResponseMsg;
                    Text = msg.ExceptionData.Message;
                }
                stats.AddOrUpdate(call.CallSlot.CallStatus, 1, (_, k) => k + 1);
            }

            var sb = new StringBuilder();

            foreach (var k in stats.Keys)
            {
                sb.AppendLine("{0} = {1} times".Args(k, stats[k]));
            }

            tbNote.Text += sb.ToString();

            var allFinished = w.ElapsedMilliseconds;

            Text = "Placed {0:n2} calls in {1:n2} ms, then waited {2:n2} ms for finish, total time {3:n2} ms @ {4:n2} calls/sec "
                   .Args
                   (
                totalCalls,
                callsPlaced,
                allFinished - callsPlaced,
                allFinished,
                totalCalls / (allFinished / 1000d)
                   );
        }