예제 #1
0
        static void Main(string[] args)
        {
            MessageStore <object> ms = new MessageStore <object>(capacity: 80000);

            ThreadPool.SetMinThreads(32, 32);

            Console.WriteLine("{0}-bit process", IntPtr.Size * 8);
            Console.WriteLine("{0} writer(s), {1} reader(s)", NumWriters, NumReaders);
            Console.WriteLine("Running for {0}..", RunTime);

            // queue writers
            for (int writerNum = 0; writerNum < NumWriters; writerNum++)
            {
                ThreadPool.QueueUserWorkItem(_ =>
                {
                    for (int i = 0; ; i++)
                    {
                        ms.Add("This is my awesome object!");
                    }
                }, null);
            }

            // queue readers
            long totalMessagesRecvd = 0;

            for (int readerNum = 0; readerNum < NumReaders; readerNum++)
            {
                ThreadPool.QueueUserWorkItem(_ =>
                {
                    ulong firstMessageIdToReceive = 0;
                    while (true)
                    {
                        var x = ms.GetMessages(firstMessageIdToReceive);
                        ulong firstMessageIdReceived = x.FirstMessageId;
                        firstMessageIdToReceive      = firstMessageIdReceived + (ulong)x.Messages.Length;

                        if (x.Messages.Length > 0)
                        {
                            Interlocked.Add(ref totalMessagesRecvd, x.Messages.Length);
                        }
                        else
                        {
                            // back off if there is no more data
                            Thread.Sleep(10);
                        }
                    }
                }, null);
            }

            // let the program run for 10 seconds
            Thread.Sleep(RunTime);
            ulong totalMessagesWritten = ms.GetMessageCount();

            Console.WriteLine();
            Console.WriteLine("Throughput:");
            Console.WriteLine("{0:N0} total messages written", totalMessagesWritten);
            Console.WriteLine("  ({0:N0} messages per writer per second)", totalMessagesWritten / RunTime.TotalSeconds / NumWriters);
            Console.WriteLine("{0:N0} total messages received", totalMessagesRecvd);
            Console.WriteLine("  ({0:N0} messages per reader per second)", totalMessagesRecvd / RunTime.TotalSeconds / NumReaders);
        }
        static void Main(string[] args)
        {
            try
            {
                if (args.Length == 1)
                {
                    MessageStore store = new MessageStore();
                    store.SaveMessage(Environment.UserName + "@" + Environment.MachineName, args[0]);
                }
                else if (args.Length == 0)
                {
                    MessageStore store    = new MessageStore();
                    DataSet      messages = store.GetMessages();

                    foreach (DataRow record in messages.Tables[0].Rows)
                    {
                        string line = String.Format("On {0} {1} said '{2}'",
                                                    ((DateTime)record["LoggedDate"]).ToString(),
                                                    record["Name"],
                                                    record["Comments"]);
                        Console.WriteLine(line);
                    }
                }
                else
                {
                    Console.Error.WriteLine("Usage: Comment.exe comments");
                }
            }
            catch (Exception e) {
                Console.Error.WriteLine(errorMsg, e.Message, e.Source);
            }
        }
 private void OnPreRender(object sender, System.EventArgs e)
 {
     SuccessLabel.Visible = (SuccessLabel.Visible & Page.IsPostBack);
     //Retrieve DataSet and bind to datagrid control...
     this.MessageGrid.DataSource = dataStore.GetMessages();
     this.MessageGrid.DataBind();
 }
예제 #4
0
        static void Main(string[] args)
        {
            MessageStore<object> ms = new MessageStore<object>(capacity: 80000);
            ThreadPool.SetMinThreads(32, 32);

            Console.WriteLine("{0}-bit process", IntPtr.Size * 8);
            Console.WriteLine("{0} writer(s), {1} reader(s)", NumWriters, NumReaders);
            Console.WriteLine("Running for {0}..", RunTime);

            // queue writers
            for (int writerNum = 0; writerNum < NumWriters; writerNum++)
            {
                ThreadPool.QueueUserWorkItem(_ =>
                {
                    for (int i = 0; ; i++)
                    {
                        ms.Add("This is my awesome object!");
                    }
                }, null);
            }

            // queue readers
            long totalMessagesRecvd = 0;
            for (int readerNum = 0; readerNum < NumReaders; readerNum++)
            {
                ThreadPool.QueueUserWorkItem(_ =>
                {
                    ulong firstMessageIdToReceive = 0;
                    while (true)
                    {
                        var x = ms.GetMessages(firstMessageIdToReceive);
                        ulong firstMessageIdReceived = x.FirstMessageId;
                        firstMessageIdToReceive = firstMessageIdReceived + (ulong)x.Messages.Length;

                        if (x.Messages.Length > 0)
                        {
                            Interlocked.Add(ref totalMessagesRecvd, x.Messages.Length);
                        }
                        else
                        {
                            // back off if there is no more data
                            Thread.Sleep(10);
                        }

                    }
                }, null);
            }

            // let the program run for 10 seconds
            Thread.Sleep(RunTime);
            ulong totalMessagesWritten = ms.GetMessageCount();

            Console.WriteLine();
            Console.WriteLine("Throughput:");
            Console.WriteLine("{0:N0} total messages written", totalMessagesWritten);
            Console.WriteLine("  ({0:N0} messages per writer per second)", totalMessagesWritten / RunTime.TotalSeconds / NumWriters);
            Console.WriteLine("{0:N0} total messages received", totalMessagesRecvd);
            Console.WriteLine("  ({0:N0} messages per reader per second)", totalMessagesRecvd / RunTime.TotalSeconds / NumReaders);
        }