/* Join a group. The group context is returned in *contextp. */ internal void Join(Member m, JoinOps ops) { lock (send_mutex) { /* Check that this is a fresh Member, e.g., we haven't already * joined a group with it. */ if (m.current_status != Member.Status.Pre) { throw new EnsembleException("Trying to Join more than once"); } // Update the state of the member to Joining m.current_status = Member.Status.Joining; // We must provide the member with an ID prior to any other operation m.id = AllocMid(); WriteBegin(); // Write the downcall. WriteHdr(m, DnType.DN_JOIN); WriteString(ops.group_name); WriteString(ops.properties); WriteString(ops.parameters); WriteString(ops.princ); WriteBool(ops.secure); WriteEnd(); // Add the member to the hashtable. This will allow // finding it when messages arrive on the socket. ContextAdd(m); } }
public static void Main(string[] args) { conn = new Connection (); conn.Connect(); JoinOps jops = new JoinOps(); jops.group_name = "CS_Mtalk" ; // Create the endpoint memb = new Member(conn); memb.Join(jops); MainLoop(); }
/** A simple test case. Invoke with a number of group names. * Each member will cast the group name every second. */ public static void Main(string[] args) { ParseCmdLine (args); conn = new Connection (); conn.Connect(); JoinOps jops = new JoinOps(); jops.group_name = "CS_Perf" ; // Create the endpoint memb = new Member(conn); if (prog == "rpc") RpcMainLoop(jops); else ThrouMainLoop(jops); }
// Create an endpoint in slot [i] static void CreateEndpt(int i) { JoinOps jops = new JoinOps(); jops.group_name = groupName; Member m = new Member(conn); m.Join(jops); memb_a[i] = m; Console.WriteLine("Join"); }
/**************************************************************/ /* Throuput test case */ static void ThrouMainLoop(JoinOps jops) { memb.Join(jops); while (true) { // handle all incoming messages while (conn.Poll ()) { Message msg = conn.Recv (); switch (msg.mtype) { case UpType.VIEW: v = msg.view; Console.Write(" view=["); foreach (string endpt in v.view) { System.Console.Write(":" + endpt); } Console.WriteLine("]"); blocked = false ; if (nmembers == v.nmembers) { start = true ; start_time = DateTime.Now.Ticks; bulk_data= new byte[size] ; Console.WriteLine("Got initial membership"); } if (nmembers > v.nmembers && start) { Console.WriteLine("Members have started to leave, exiting."); System.Diagnostics.Process currentProcess = System.Diagnostics.Process.GetCurrentProcess(); currentProcess.Kill(); } break; case UpType.EXIT: Console.WriteLine("RPC exit"); break; case UpType.CAST: num_recvd_msgs++; total+=size; if (num_recvd_msgs% 10 == 0) Console.WriteLine("#recv_cast: " + num_recvd_msgs); if (start && num_recvd_msgs == total_num_msgs && 1 == v.rank) { start = false ; long now = DateTime.Now.Ticks; long diff = (now -start_time)/(10*1000*1000); Console.WriteLine("finished Throuput test"); Console.WriteLine("total=" + total ); Console.WriteLine("time=" + diff + "sec"); Console.WriteLine("throughput=" + (int) total/(1024 * diff) + "Kbyte/sec"); memb.Leave(); Thread.Sleep(1000); System.Diagnostics.Process currentProcess = System.Diagnostics.Process.GetCurrentProcess(); currentProcess.Kill(); } break; case UpType.SEND: break; case UpType.BLOCK: blocked = true ; memb.BlockOk(); break; } } // multicast the message periodically. if (start && !blocked && v.nmembers == nmembers && 0 == v.rank && !done) { Console.WriteLine("Mulitcasting messages\n"); for (int i=0; i<total_num_msgs; i++) memb.Cast(bulk_data); done = true; } } }
/**************************************************************/ /* RPC test case */ static void RpcMainLoop(JoinOps jops) { memb.Join(jops); while (true) { Message msg = conn.Recv (); switch (msg.mtype) { case UpType.VIEW: v = msg.view; Console.Write(" view=["); foreach (string endpt in v.view) { System.Console.Write(":" + endpt); } Console.WriteLine("]"); blocked = false ; if (2 == v.nmembers) { start = true ; start_time = DateTime.Now.Ticks; bulk_data= new byte[size] ; Console.WriteLine("Got initial membership"); } if (start && 0 == v.rank) { Console.WriteLine("Sending first message"); memb.Send1(1, bulk_data); } break; case UpType.EXIT: Console.WriteLine("RPC exit"); break; case UpType.CAST: break; case UpType.SEND: num_recvd_msgs++; if (num_recvd_msgs % 1000 == 0) Console.WriteLine("#recv_send: " + num_recvd_msgs); if (start && !blocked && v.nmembers == 2) { if (v.rank == 0) memb.Send1(1, bulk_data); if (v.rank == 1) memb.Send1(0, bulk_data); } if (start && num_recvd_msgs >= total_num_msgs) { start = false ; long now = DateTime.Now.Ticks; long diff = (now -start_time)/(10*1000*1000); Console.WriteLine("finished RPC test"); Console.WriteLine("total=" + num_recvd_msgs); Console.WriteLine("time=" + diff + "sec"); Console.WriteLine("round-trip latency=" + (double)((diff*1000*1000)/num_recvd_msgs)+ "(mircosecond)"); // conn.Leave(memb); Thread.Sleep(1000); System.Diagnostics.Process currentProcess = System.Diagnostics.Process.GetCurrentProcess(); currentProcess.Kill(); } break; case UpType.BLOCK: blocked = true ; memb.BlockOk(); break; } } }
/// <summary> Join a group </summary> /// <param name="ops"> The join options passed to Ensemble. </param> public void Join(JoinOps ops) { conn.Join(this, ops); }
/* Join a group. The group context is returned in *contextp. */ internal void Join(Member m, JoinOps ops) { lock(send_mutex) { /* Check that this is a fresh Member, e.g., we haven't already * joined a group with it. */ if (m.current_status != Member.Status.Pre) throw new EnsembleException("Trying to Join more than once"); // Update the state of the member to Joining m.current_status = Member.Status.Joining; // We must provide the member with an ID prior to any other operation m.id = AllocMid(); WriteBegin(); // Write the downcall. WriteHdr(m,DnType.DN_JOIN); WriteString(ops.group_name); WriteString(ops.properties); WriteString(ops.parameters); WriteString(ops.princ); WriteBool(ops.secure); WriteEnd(); // Add the member to the hashtable. This will allow // finding it when messages arrive on the socket. ContextAdd(m); } }