Ejemplo n.º 1
0
        async Task t001_TestIntensiveParallel()
        {
            System.Diagnostics.Stopwatch sw = null;
            List <byte[]> mll = new List <byte[]>();


            //var uzuz = sm.RemoteRequest(new byte[] { 50 }, (Tuple<bool, byte[]> myres1) =>
            //{
            //    Console.WriteLine("received");
            //}, timeoutMs: 10000);


            //return;

            //var uzuz = await sm.RemoteRequestAsync(new byte[1700]);
            //return;

            //Parallel.For(0, 100, async (aii) => {
            //    for (int j = 0; j < 1000; j++)
            //    {
            //        //var tor = sm.RemoteRequest(new byte[50]);
            //        var tor = await sm.RemoteRequestAsync(new byte[50], null);
            //        //Console.WriteLine(DateTime.UtcNow.ToString("HH:mm:ss.ms") + "> masterRes " +tor.Item1 + " " + tor.Item2.Length);
            //    }
            //});


            sw = new System.Diagnostics.Stopwatch();
            sw.Start();
            for (int j = 0; j < 10000; j++)
            {
                //var tor = sm.RemoteRequest(new byte[1]);
                var tor = await sm.RemoteRequestAsync(new byte[1] {
                    17
                });

                //mll.Add(tor.Item2);
            }
            sw.Stop();
            Console.WriteLine("ELAPS: " + sw.ElapsedMilliseconds);
            MessageBox.Show("ELAPS: " + sw.ElapsedMilliseconds);

            return;


            //sw = new System.Diagnostics.Stopwatch();
            //sw.Start();

            //for (int j = 0; j < 10000; j++)
            //{
            //    var tor = await sm.RemoteRequestAsync(new byte[1]);

            //}
            //sw.Stop();
            ////Console.WriteLine("ELAPS: " + sw.ElapsedMilliseconds);
            //MessageBox.Show("ELAPS: " + sw.ElapsedMilliseconds);
            //return;



            //sw = new System.Diagnostics.Stopwatch();
            //sw.Start();
            //for (int j = 0; j < 20000; j++)
            //{
            //    var tor = sm.RemoteRequest(new byte[1], null);

            //}
            //sw.Stop();
            //MessageBox.Show("ELAPS: " + sw.ElapsedMilliseconds);
            //Console.WriteLine("ELAPS: " + sw.ElapsedMilliseconds);
            //return;



            //sw = new System.Diagnostics.Stopwatch();
            //sw.Start();
            //for (int j = 0; j < 1000; j++)
            //{
            //    var tor = sm.RemoteRequest(new byte[50], (ans) => {

            //    });

            //}
            //sw.Stop();
            //MessageBox.Show("ELAPS: " + sw.ElapsedMilliseconds);
            ////Console.WriteLine("ELAPS: " + sw.ElapsedMilliseconds);
            //return;



            //System.Threading.ThreadPool.SetMinThreads(100, 100);

            var tasks = new List <Task>();

            //Action a = () =>
            //{
            //    for (int j = 0; j < 10000; j++)
            //    {
            //        var tor = sm.RemoteRequest(new byte[1]);

            //        //var tor = sm.RemoteRequest(new byte[50],(par) => {
            //        //});
            //        //Console.WriteLine(DateTime.UtcNow.ToString("HH:mm:ss.ms") + "> masterRes " +tor.Item1 + " " + tor.Item2.Length);
            //    }
            //};

            //var t = Task.Run(() => { sm.RemoteRequest(new byte[50]); });
            for (int i = 0; i < 5; i++)
            {
                int index = i;
                //tasks.Add(Task.Factory.StartNew(a));

                //tasks.Add(Task.Factory.StartNew(RunMeManyAsync));
                tasks.Add(Task.Run(() => RunMeManyAsync()));
                //tasks.Add(RunMeManyAsync());
            }

            sw = new System.Diagnostics.Stopwatch();
            sw.Start();
            await Task.WhenAll(tasks.ToArray());

            sw.Stop();
            Console.WriteLine("ELAPS: " + sw.ElapsedMilliseconds);
            MessageBox.Show("ELAPS: " + sw.ElapsedMilliseconds);
        }