コード例 #1
0
ファイル: Program.cs プロジェクト: Eckankar/pcsd-2012
        static void Main(string[] args)
        {
            KeyValueBaseServiceClient client = new KeyValueBaseServiceClient();

            client.Reset();
            client.Init(TEST_FILE);

            StreamWriter sw = new StreamWriter(@"C:\Users\jacob\lots-of-clients_100reqs_zipf0.5.txt", false);

            for (int num = 1; num <= 25; num++)
            {
                sw.WriteLine("== {0} simultaneous workers ==", num);
                Console.WriteLine("== {0} simultaneous workers ==", num);

                BackgroundWorker[] bws = new BackgroundWorker[num];

                numLeft = num;

                for (int i = 0; i < num; i++)
                {
                    bws[i]         = new BackgroundWorker();
                    bws[i].DoWork += (obj, arg) => {
                        KeyValueBaseServiceClient workerClient = new KeyValueBaseServiceClient();
                        int       workerNum = (int)arg.Argument;
                        Stopwatch watch     = Stopwatch.StartNew();

                        for (int j = 0; j < NUM_ACCESSES; j++)
                        {
                            KeyImpl key = new KeyImpl()
                            {
                                Key = ids[workerNum, j]
                            };
                            workerClient.Read(key);
                        }

                        watch.Stop();
                        lock (sw) {
                            sw.WriteLine("{1}", workerNum, watch.ElapsedMilliseconds);
                        }

                        Interlocked.Decrement(ref numLeft);
                    };

                    bws[i].RunWorkerAsync(i);
                }

                while (numLeft > 0)
                {
                    Thread.Sleep(100);
                }
            }

            sw.Flush();
            sw.Close();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: Eckankar/pcsd-2012
        static void Main(string[] args)
        {
            KeyValueBaseServiceClient client = new KeyValueBaseServiceClient();
            client.Reset();
            client.Init(TEST_FILE);

            StreamWriter sw = new StreamWriter(@"C:\Users\jacob\lots-of-clients_100reqs_zipf0.5.txt", false);

            for (int num = 1; num <= 25; num++) {
                sw.WriteLine("== {0} simultaneous workers ==", num);
                Console.WriteLine("== {0} simultaneous workers ==", num);

                BackgroundWorker[] bws = new BackgroundWorker[num];

                numLeft = num;

                for (int i = 0; i < num; i++) {
                    bws[i] = new BackgroundWorker();
                    bws[i].DoWork += (obj, arg) => {

                        KeyValueBaseServiceClient workerClient = new KeyValueBaseServiceClient();
                        int workerNum = (int)arg.Argument;
                        Stopwatch watch = Stopwatch.StartNew();

                        for (int j = 0; j < NUM_ACCESSES; j++) {
                            KeyImpl key = new KeyImpl() { Key = ids[workerNum, j] };
                            workerClient.Read(key);
                        }

                        watch.Stop();
                        lock (sw) {
                            sw.WriteLine("{1}", workerNum, watch.ElapsedMilliseconds);
                        }

                        Interlocked.Decrement(ref numLeft);
                    };

                    bws[i].RunWorkerAsync(i);
                }

                while (numLeft > 0) {
                    Thread.Sleep(100);
                }
            }

            sw.Flush();
            sw.Close();
        }
コード例 #3
0
        public static void Main(string[] args)
        {
            KeyValueBaseServiceClient client = new KeyValueBaseServiceClient();

            while (true)
            {
                try {
                    Console.Write("Enter command: ");
                    string   line  = Console.ReadLine();
                    string[] parts = line.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                    if (parts.Length == 0)
                    {
                        continue;
                    }
                    string cmd = parts[0];
                    if (cmd == "init")
                    {
                        client.Init(line.Split(new char[] { ' ', '\t' }, 2, StringSplitOptions.RemoveEmptyEntries)[1]);
                    }
                    else if (cmd == "reset")
                    {
                        client.Reset();
                    }
                    else if (cmd == "read")
                    {
                        KeyImpl key = ParseKey(parts[1]);
                        PrintList(client.Read(key));
                    }
                    else if (cmd == "insert")
                    {
                        KeyImpl       key    = ParseKey(parts[1]);
                        ValueListImpl values = ParseList(parts, 2);
                        client.Insert(key, values);
                    }
                    else if (cmd == "update")
                    {
                        KeyImpl       key    = ParseKey(parts[1]);
                        ValueListImpl values = ParseList(parts, 2);
                        client.Update(key, values);
                    }
                    else if (cmd == "delete")
                    {
                        KeyImpl key = ParseKey(parts[1]);
                        client.Delete(key);
                    }
                    else if (cmd == "scan" || cmd == "atomicscan")
                    {
                        bool    atomic = cmd == "atomicscan";
                        KeyImpl begin  = ParseKey(parts[1]);
                        KeyImpl end    = ParseKey(parts[2]);

                        string          predicateString = line.Split(new char[] { ' ', '\t' }, 4, StringSplitOptions.RemoveEmptyEntries)[3];
                        object          predicate       = TokenizeAndParsePredicate(predicateString);
                        ValueListImpl[] lists;
                        if (atomic)
                        {
                            lists = client.AtomicScan(begin, end, predicate);
                        }
                        else
                        {
                            lists = client.Scan(begin, end, predicate);
                        }
                        foreach (ValueListImpl vl in lists)
                        {
                            PrintList(vl);
                        }
                    }
                    else if (cmd == "close" || cmd == "quit" || cmd == "exit")
                    {
                        break;
                    }
                    else
                    {
                        Console.WriteLine("?");
                    }
                }
                catch (Exception e) {
                    Console.WriteLine(e.ToString());
                }
            }

            client.Close();
        }