Exemplo n.º 1
0
        protected override void Experiment(ulong id, ulong num_keys, ulong size_value, char workload)
        {
            ulong request_key = 150;
            int   serverIdx   = 0;
            ulong seq_num     = 0;

            this.udpClient = new System.Net.Sockets.UdpClient(6000 + (int)id);
            this.udpClient.Client.ReceiveTimeout = 0;
            uint SIO_UDP_CONNRESET = 0x9800000C; // suppress UDP "connection" closed exceptions, since UDP is connectionless

            this.udpClient.Client.IOControl((System.Net.Sockets.IOControlCode)SIO_UDP_CONNRESET, new byte[] { 0 }, new byte[0]);
            this.udpClient.Client.ReceiveBufferSize = 8192 * 100;

            ulong myaddr = MyAddress64();


            // Test the functionality of the Sharding
            if (workload == 'f')
            {
                ulong k_lo      = 100;
                ulong k_hi      = 200;
                var   recipient = EncodeIpPort(ClientBase.endpoints[(serverIdx + 1) % ClientBase.endpoints.Count()]);

                seq_num++;

                var msg = new GetRequestMessage(seq_num, myaddr, request_key);
                this.Send(msg, ClientBase.endpoints[serverIdx]);
                ReceiveReply(serverIdx, myaddr, request_key, false);

                seq_num++;

                Console.WriteLine("Sending a Shard request with a sequence number {0}", seq_num);
                var shardMessage = new ShardRequestMessage(seq_num, myaddr, k_lo, k_hi, recipient);
                this.Send(shardMessage, ClientBase.endpoints[serverIdx]);
                ReceiveReply(serverIdx, myaddr, request_key, true);

                Thread.Sleep(5000);


                Console.WriteLine("Sending a GetRequest after a Shard, expect a redirect");
                seq_num++;
                msg = new GetRequestMessage(seq_num, myaddr, request_key);
                this.Send(msg, ClientBase.endpoints[(serverIdx + 0) % ClientBase.endpoints.Count()]);
                ReceiveReply(serverIdx, myaddr, request_key, false);

                Thread.Sleep(5000);

                Console.WriteLine("Sending a GetRequest after a Shard to the second host, expect a reply");
                seq_num = 1;
                msg     = new GetRequestMessage(seq_num, myaddr, request_key);
                this.Send(msg, ClientBase.endpoints[(serverIdx + 1) % ClientBase.endpoints.Count()]);
                ReceiveReply(serverIdx, myaddr, request_key, false);

                return;
            }

            // Run an actual workload
            while (true)
            {
                var received_reply = false;
                request_key = seq_num % num_keys;

                seq_num++;

                MessageBase msg;
                if (workload == 'g')
                {
                    msg = new GetRequestMessage(seq_num, myaddr, request_key);
                }
                else
                {
                    msg = new SetRequestMessage(seq_num, myaddr, request_key, size_value);
                }

                var start_time = HiResTimer.Ticks;
                this.Send(msg, ClientBase.endpoints[serverIdx]);

                // Wait for the reply

                while (!received_reply)
                {
                    byte[] bytes;
                    try
                    {
                        bytes = Receive();
                    }
                    catch (System.Net.Sockets.SocketException e)
                    {
                        //serverIdx = (serverIdx + 1) % ClientBase.endpoints.Count();
                        //Console.WriteLine("#timeout; rotating to server {0}", serverIdx);
                        //Console.WriteLine(e.ToString());
                        Console.WriteLine("#timeout; retrying {0}", serverIdx);
                        continue;
                    }
                    var end_time = HiResTimer.Ticks;

                    if (bytes.Length == 16)
                    {
                        //Ignore acks
                    }
                    else if (bytes.Length >= 56)
                    {
                        var reply_seqno = ExtractBE64(bytes, offset: 8);
                        //Console.Out.WriteLine("Reply sequence number : " + reply_seqno);


                        //Console.Out.WriteLine("Client " + id.ToString() + ": Sending an ack with a sequence number " + reply_seqno + " to " + ClientBase.endpoints[serverIdx].ToString());
                        if (seq_num % 100 == 0)
                        {
                            var ack_msg = new AckMessage(reply_seqno, myaddr);
                            this.Send(ack_msg, ClientBase.endpoints[serverIdx]);
                        }

                        var reply_key = ExtractBE64(bytes, offset: 32);
                        // Need to send an ack
                        //Console.Out.WriteLine("Request key : " + request_key);
                        //Console.Out.WriteLine("Reply key : " + reply_key);

                        //Console.Out.WriteLine("Got packet length: " + bytes.Length);
                        // key is the same as the sequence number
                        if (reply_key == request_key)
                        {
                            received_reply = true;
                            Console.Out.WriteLine(string.Format("#req{0} {1} {2} {3}", seq_num, (start_time * 1.0 / Stopwatch.Frequency * Math.Pow(10, 3)), (end_time * 1.0 / Stopwatch.Frequency * Math.Pow(10, 3)), id));
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        protected override void Experiment(ulong id, ulong num_keys, ulong size_value, char workload)
        {
            ulong request_key = 150;
            int serverIdx = 0;
            ulong seq_num = 0;
            
            this.udpClient = new System.Net.Sockets.UdpClient(6000 + (int)id);
            this.udpClient.Client.ReceiveTimeout = 0;
            uint SIO_UDP_CONNRESET = 0x9800000C; // suppress UDP "connection" closed exceptions, since UDP is connectionless
            this.udpClient.Client.IOControl((System.Net.Sockets.IOControlCode)SIO_UDP_CONNRESET, new byte[] { 0 }, new byte[0]);
            this.udpClient.Client.ReceiveBufferSize = 8192 * 100;

            ulong myaddr = MyAddress64();
            
            
            // Test the functionality of the Sharding
            if (workload == 'f')
            {
                ulong k_lo = 100;
                ulong k_hi = 200;
                var recipient = EncodeIpPort(ClientBase.endpoints[(serverIdx + 1) % ClientBase.endpoints.Count()]);

                seq_num++;

                var msg = new GetRequestMessage(seq_num, myaddr, request_key);
                this.Send(msg, ClientBase.endpoints[serverIdx]);
                ReceiveReply(serverIdx, myaddr, request_key, false);

                seq_num++;
            
                Console.WriteLine("Sending a Shard request with a sequence number {0}", seq_num);
                var shardMessage = new ShardRequestMessage(seq_num, myaddr, k_lo, k_hi, recipient);
                this.Send(shardMessage, ClientBase.endpoints[serverIdx]);
                ReceiveReply(serverIdx, myaddr, request_key, true);

                Thread.Sleep(5000);
                

                Console.WriteLine("Sending a GetRequest after a Shard, expect a redirect");
                seq_num++;
                msg = new GetRequestMessage(seq_num, myaddr, request_key);
                this.Send(msg, ClientBase.endpoints[(serverIdx + 0) % ClientBase.endpoints.Count()]);
                ReceiveReply(serverIdx, myaddr, request_key, false);

                Thread.Sleep(5000);

                Console.WriteLine("Sending a GetRequest after a Shard to the second host, expect a reply");
                seq_num = 1;
                msg = new GetRequestMessage(seq_num, myaddr, request_key);
                this.Send(msg, ClientBase.endpoints[(serverIdx + 1) % ClientBase.endpoints.Count()]);
                ReceiveReply(serverIdx, myaddr, request_key, false);
                
                return;
            }

            // Run an actual workload
            while (true)
            {
                var received_reply = false;
                request_key = seq_num % num_keys;

                seq_num++;
                               
                MessageBase msg;
                if (workload == 'g') 
                {
                    msg = new GetRequestMessage(seq_num, myaddr, request_key);
                }
                else
                {
                    msg = new SetRequestMessage(seq_num, myaddr, request_key, size_value);
                }
                
                var start_time = HiResTimer.Ticks;
                this.Send(msg, ClientBase.endpoints[serverIdx]);
                
                // Wait for the reply
                
                while (!received_reply)
                {
                    byte[] bytes;
                    try
                    {
                        bytes = Receive();
                    }
                    catch (System.Net.Sockets.SocketException e)
                    {
                        //serverIdx = (serverIdx + 1) % ClientBase.endpoints.Count();
                        //Console.WriteLine("#timeout; rotating to server {0}", serverIdx);
                        //Console.WriteLine(e.ToString());
                        Console.WriteLine("#timeout; retrying {0}", serverIdx);
                        continue;
                    }
                    var end_time = HiResTimer.Ticks;
                    
                    if (bytes.Length == 16)
                    {
                        //Ignore acks
                    }
                    else if (bytes.Length >= 56) 
                    {
                        var reply_seqno = ExtractBE64(bytes, offset: 8);
                        //Console.Out.WriteLine("Reply sequence number : " + reply_seqno);
                                          

                        //Console.Out.WriteLine("Client " + id.ToString() + ": Sending an ack with a sequence number " + reply_seqno + " to " + ClientBase.endpoints[serverIdx].ToString());
                        if (seq_num % 100 == 0)
                        {
                            var ack_msg = new AckMessage(reply_seqno, myaddr);
                            this.Send(ack_msg, ClientBase.endpoints[serverIdx]);
                        }
                        
                        var reply_key = ExtractBE64(bytes, offset: 32);
                        // Need to send an ack
                        //Console.Out.WriteLine("Request key : " + request_key);
                        //Console.Out.WriteLine("Reply key : " + reply_key);

                        //Console.Out.WriteLine("Got packet length: " + bytes.Length);
                        // key is the same as the sequence number
                        if (reply_key == request_key)
                        {
                            received_reply = true;
                            Console.Out.WriteLine(string.Format("#req{0} {1} {2} {3}", seq_num, (start_time * 1.0 / Stopwatch.Frequency * Math.Pow(10, 3)), (end_time * 1.0 / Stopwatch.Frequency * Math.Pow(10, 3)), id));
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        protected override void Setup(ulong id, ulong num_keys, ulong size_value)
        {
            ulong seq_num = 0;

            this.udpClient = new System.Net.Sockets.UdpClient(7000 + (int)id);
            this.udpClient.Client.ReceiveTimeout = 1000;
            ulong myaddr = MyAddress64();

            int serverIdx = 0;

            while (seq_num < num_keys)
            {
                var request_key = seq_num % num_keys;

                seq_num++;
                var msg = new SetRequestMessage(seq_num, myaddr, request_key, size_value);

                this.Send(msg, ClientBase.endpoints[serverIdx]);

                // Wait for the reply
                var received_reply = false;
                while (!received_reply)
                {
                    byte[] bytes;
                    try
                    {
                        bytes = Receive();
                    }
                    catch (System.Net.Sockets.SocketException e)
                    {
                        //serverIdx = (serverIdx + 1) % ClientBase.endpoints.Count();
                        Console.WriteLine("#timeout; retrying {0}", serverIdx);
                        Console.WriteLine(e.ToString());
                        continue;
                    }
                    var end_time = HiResTimer.Ticks;
                    //Trace("Got the following reply:" + ByteArrayToString(bytes));
                    //Console.Out.WriteLine("Got packet length: " + bytes.Length);
                    if (bytes.Length == 16)
                    {
                        //Ignore acks
                    }
                    else if (bytes.Length >= 48)
                    {
                        var reply_seqno = ExtractBE64(bytes, offset: 8);
                        //Console.Out.WriteLine("Reply sequence number : " + reply_seqno);

                        var ack_msg = new AckMessage(reply_seqno, myaddr);

                        //Console.Out.WriteLine("Client " + id.ToString() + ": Sending an ack with a sequence number " + reply_seqno + " to " + ClientBase.endpoints[serverIdx].ToString());
                        this.Send(ack_msg, ClientBase.endpoints[serverIdx]);


                        var reply_key = ExtractBE64(bytes, offset: 32);
                        // Need to send an ack
                        //Console.Out.WriteLine("Request key : " + request_key);
                        //Console.Out.WriteLine("Reply key : " + reply_key);

                        //Console.Out.WriteLine("Got packet length: " + bytes.Length);
                        if (reply_key == request_key)
                        {
                            received_reply = true;
                            // Report time in milliseconds, since that's what the Python script appears to expect
                            //Console.Out.WriteLine(string.Format("#req{0} {1} {2} {3}", seq_num, (ulong)(start_time * 1.0 / Stopwatch.Frequency * Math.Pow(10, 3)), (ulong)(end_time * 1.0 / Stopwatch.Frequency * Math.Pow(10, 3)), id));
                        }
                    }
                }
            }

            this.udpClient.Close();
        }
Exemplo n.º 4
0
        protected override void Setup(ulong id, ulong num_keys, ulong size_value)
        {
            ulong seq_num = 0;            

            this.udpClient = new System.Net.Sockets.UdpClient(7000+(int)id);
            this.udpClient.Client.ReceiveTimeout = 1000;
            ulong myaddr = MyAddress64();
            
            int serverIdx = 0;

            while (seq_num < num_keys)
            {
                var request_key = seq_num % num_keys;

                seq_num++;
                var msg = new SetRequestMessage(seq_num, myaddr, request_key, size_value);
                
                this.Send(msg, ClientBase.endpoints[serverIdx]);
                
                // Wait for the reply
                var received_reply = false;
                while (!received_reply)
                {
                    byte[] bytes;
                    try
                    {
                        bytes = Receive();
                    }
                    catch (System.Net.Sockets.SocketException e)
                    {
                        //serverIdx = (serverIdx + 1) % ClientBase.endpoints.Count();
                        Console.WriteLine("#timeout; retrying {0}", serverIdx);
                        Console.WriteLine(e.ToString());
                        continue;
                    }
                    var end_time = HiResTimer.Ticks;
                    //Trace("Got the following reply:" + ByteArrayToString(bytes));
                    //Console.Out.WriteLine("Got packet length: " + bytes.Length);
                    if (bytes.Length == 16)
                    {
                        //Ignore acks
                    }
                    else if (bytes.Length >= 48) 
                    {
                        var reply_seqno = ExtractBE64(bytes, offset: 8);
                        //Console.Out.WriteLine("Reply sequence number : " + reply_seqno);

                        var ack_msg = new AckMessage(reply_seqno, myaddr);

                        //Console.Out.WriteLine("Client " + id.ToString() + ": Sending an ack with a sequence number " + reply_seqno + " to " + ClientBase.endpoints[serverIdx].ToString());
                        this.Send(ack_msg, ClientBase.endpoints[serverIdx]);


                        var reply_key = ExtractBE64(bytes, offset: 32);
                        // Need to send an ack
                        //Console.Out.WriteLine("Request key : " + request_key);
                        //Console.Out.WriteLine("Reply key : " + reply_key);

                        //Console.Out.WriteLine("Got packet length: " + bytes.Length);
                        if (reply_key == request_key)
                        {
                            received_reply = true;
                            // Report time in milliseconds, since that's what the Python script appears to expect
                            //Console.Out.WriteLine(string.Format("#req{0} {1} {2} {3}", seq_num, (ulong)(start_time * 1.0 / Stopwatch.Frequency * Math.Pow(10, 3)), (ulong)(end_time * 1.0 / Stopwatch.Frequency * Math.Pow(10, 3)), id));
                        }
                    }
                }
            }

            this.udpClient.Close();
        }