예제 #1
0
파일: GDIDGen.cs 프로젝트: saleyn/agni
        private void _parallelGenerationDifferent()
        {
            const int PASS_CNT = 5000;

            int TOTAL = 0;

            var gen = new GDIDGenerator("AAAA", null);

            gen.AuthorityHosts.Register(new GDIDGenerator.AuthorityHost("sync://127.0.0.1:9999"));

            var dict = new Dictionary <string, List <ulong> >();

            dict.Add("aseq", new List <ulong>());
            dict.Add("bseq", new List <ulong>());
            dict.Add("cseq", new List <ulong>());
            dict.Add("dseq", new List <ulong>());
            dict.Add("eseq", new List <ulong>());
            dict.Add("fseq", new List <ulong>());
            dict.Add("gseq", new List <ulong>());


            var rnd = new Random();

            var sw = Stopwatch.StartNew();

            Parallel.For(0, PASS_CNT,
                         (n) =>
            {
                var seq = dict.Keys.ToList()[n % dict.Keys.Count];

                var BATCH   = 32 + rnd.Next(255);         //introduces randomness in threads
                ulong[] arr = new ulong[BATCH];

                for (int i = 0; i < BATCH; i++)
                {
                    arr[i] = gen.GenerateOneGDID("a", seq, 1024).ID;
                }

                lock (dict[seq])
                    foreach (var id in arr)
                    {
                        dict[seq].Add(id);
                    }

                System.Threading.Interlocked.Add(ref TOTAL, BATCH);
            });

            var elapsed = sw.ElapsedMilliseconds;

            foreach (var kvp in dict)
            {
                Aver.AreEqual(kvp.Value.Count, kvp.Value.Distinct().Count());//all values are distinct
                Console.WriteLine("{0} = {1} ids".Args(kvp.Key, kvp.Value.Count));
            }

            Console.WriteLine("Processed {0} in {1} ms. at {2}/sec.".Args(TOTAL, elapsed, TOTAL / (elapsed / 1000d)));
        }
예제 #2
0
        private void btnGenerateOne_Click(object sender, EventArgs e)
        {
            tbOutput.Text = "";

            var sw   = Stopwatch.StartNew();
            var gdid = m_Generator.GenerateOneGDID(tbNamespace.Text, tbSequence.Text, tbManyCount.Text.AsInt(0));

            var elapsedMs = sw.ElapsedTicks / ((double)Stopwatch.Frequency / 1000d);

            tbOutput.AppendText("Elapsed {0:n3}msec".Args(elapsedMs));


            tbOutput.AppendText("{0}\r\n".Args(gdid));
        }
예제 #3
0
파일: GDIDGen.cs 프로젝트: saleyn/agni
        private void _parallelGenerationSame()
        {
            const int PASS_CNT = 5000;

            int TOTAL = 0;

            var gen = new GDIDGenerator("AAAA", null);

            gen.AuthorityHosts.Register(new GDIDGenerator.AuthorityHost("sync://127.0.0.1:9999"));

            var lst = new List <ulong>();
            var rnd = new Random();

            var sw = Stopwatch.StartNew();

            Parallel.For(0, PASS_CNT,
                         (_) =>
            {
                var BATCH   = 32 + rnd.Next(255);         //introduces randomness in threads
                ulong[] arr = new ulong[BATCH];

                for (int i = 0; i < BATCH; i++)
                {
                    arr[i] = gen.GenerateOneGDID("a", "aseq", 1024).ID;
                }

                lock (lst)
                    foreach (var id in arr)
                    {
                        lst.Add(id);
                    }

                System.Threading.Interlocked.Add(ref TOTAL, BATCH);
            });

            var elapsed = sw.ElapsedMilliseconds;


            Aver.AreEqual(lst.Count, lst.Distinct().Count());  //all values are distinct

            Console.WriteLine("Processed {0} in {1} ms. at {2}/sec.".Args(TOTAL, elapsed, TOTAL / (elapsed / 1000d)));
        }
예제 #4
0
        static void run(string[] args)
        {
            using (var app = new ServiceBaseApplication(args, null))
            {
                var silent = app.CommandArgs["s", "silent"].Exists;
                if (!silent)
                {
                    ConsoleUtils.WriteMarkupContent(typeof(ProgramBody).GetText("Welcome.txt"));

                    ConsoleUtils.Info("Build information:");
                    Console.WriteLine(" NFX:     " + BuildInformation.ForFramework);
                    Console.WriteLine(" Agni: " + new BuildInformation(typeof(Agni.AgniSystem).Assembly));
                    Console.WriteLine(" Tool:    " + new BuildInformation(typeof(agm.ProgramBody).Assembly));
                }

                if (app.CommandArgs["?", "h", "help"].Exists)
                {
                    ConsoleUtils.WriteMarkupContent(typeof(ProgramBody).GetText("Help.txt"));
                    return;
                }

                var authority          = app.CommandArgs.AttrByIndex(0).Value;
                var connectToAuthority = authority.ToResolvedServiceNode(false).ConnectString;
                var scope = app.CommandArgs.AttrByIndex(1).Value;
                var seq   = app.CommandArgs.AttrByIndex(2).Value;
                var bsize = app.CommandArgs.AttrByIndex(3).ValueAsInt(1);

                if (!silent)
                {
                    ConsoleUtils.Info("Authority:  " + authority);
                    ConsoleUtils.Info("Connect to: " + connectToAuthority);
                    ConsoleUtils.Info("Scope:      " + scope);
                    ConsoleUtils.Info("Sequence:   " + seq);
                    ConsoleUtils.Info("Block Size: " + bsize);
                }



                var w = System.Diagnostics.Stopwatch.StartNew();

                var generator = new GDIDGenerator();
                generator.AuthorityHosts.Register(new GDIDGenerator.AuthorityHost(connectToAuthority));


                var json = app.CommandArgs["j", "json"].Exists;
                var arr  = app.CommandArgs["array"].Exists;


                if (arr)
                {
                    Console.WriteLine("[");
                }

                for (var i = 0; i < bsize; i++)
                {
                    var gdid = generator.GenerateOneGDID(scope, seq, bsize - i, noLWM: true);
////System.Threading.Thread.Sleep(5);
//Console.ReadKey();
                    string line;

                    if (json)
                    {
                        line = new
                        {
                            Era       = gdid.Era,
                            ID        = gdid.ID,
                            Authority = gdid.Authority,
                            Counter   = gdid.Counter
                        }
                    }