示例#1
0
    static unsafe int Main(string [] args)
    {
        if (args.Length != 3)
        {
            Console.Out.WriteLine ("usage: cs_local_lat <hostname> " +
                "<message-size> <roundtrip-count>\n");
            return 1;
        }

        String host = args [0];
        uint messageSize = Convert.ToUInt32 (args [1]);
        int roundtripCount = Convert.ToInt32 (args [2]);

        //  Print out the test parameters.
        Console.Out.WriteLine ("message size: " + messageSize + " [B]");
        Console.Out.WriteLine ("roundtrip count: " + roundtripCount);

        //  Create 0MQ Dnzmq class.
        Zmq w = new Zmq (host);

        //  Set up 0MQ wiring.
        int exchange = w.CreateExchange ("EL", Zmq.SCOPE_LOCAL, "",
            Zmq.STYLE_LOAD_BALANCING);
        w.CreateQueue ("QL", Zmq.SCOPE_LOCAL, "",
            Zmq.NO_LIMIT, Zmq.NO_LIMIT, Zmq.NO_SWAP);
        w.Bind ("EL", "QG", null, null);
        w.Bind ("EG", "QL", null, null);

        //  Create a message to send.
        byte[] outMessage = new byte[messageSize];

        //  Start measuring the time.
        System.Diagnostics.Stopwatch watch;
        watch = new Stopwatch ();
        watch.Start ();

        byte[] inMessage;
        int type;
        //  Start sending messages.
        for (int i = 0; i < roundtripCount; i++)
        {
            w.Send (exchange, outMessage, true);
            w.Receive (out inMessage, out type, true);
            Debug.Assert (inMessage.Length == messageSize);
        }
        //  Stop measuring the time.
        watch.Stop ();
        Int64 elapsedTime = watch.ElapsedTicks;

        //  Compute and print out the latency.
        double latency = (double) (elapsedTime) / roundtripCount / 2 *
            1000000 / Stopwatch.Frequency;
        Console.Out.WriteLine ("Your average latency is {0} [us]",
            latency.ToString ("f2"));

        System.Threading.Thread.Sleep (5000);
        w.Destroy ();

        return 0;
    }
示例#2
0
    static unsafe int Main(string [] args)
    {
        if (args.Length != 3)
        {
            Console.Out.WriteLine("usage: cs_remote_thr <hostname> " +
                                  "<message-size> <message-count>\n");
            return(1);
        }

        String host        = args[0];
        uint   messageSize = Convert.ToUInt32(args[1]);
        int    msgCount    = Convert.ToInt32(args[2]);

        //  Create 0MQ Dnzmq class
        Zmq w = new Zmq(host);

        //  Set up 0MQ wiring.
        int exchange = w.CreateExchange("E", Zmq.SCOPE_LOCAL, "",
                                        Zmq.STYLE_LOAD_BALANCING);

        w.Bind("E", "Q", null, null);

        //  Create a message to send.
        byte[] message = new byte[messageSize];

        //  Start sending messages.
        for (int i = 0; i < msgCount; i++)
        {
            w.Send(exchange, message, true);
        }

        System.Threading.Thread.Sleep(10000);

        w.Destroy();
        return(0);
    }
示例#3
0
    static unsafe int Main(string [] args)
    {
        if (args.Length != 3)
        {
            Console.Out.WriteLine("usage: cs_local_lat <hostname> " +
                                  "<message-size> <roundtrip-count>\n");
            return(1);
        }

        String host           = args [0];
        uint   messageSize    = Convert.ToUInt32(args [1]);
        int    roundtripCount = Convert.ToInt32(args [2]);

        //  Print out the test parameters.
        Console.Out.WriteLine("message size: " + messageSize + " [B]");
        Console.Out.WriteLine("roundtrip count: " + roundtripCount);

        //  Create 0MQ Dnzmq class.
        Zmq w = new Zmq(host);

        //  Set up 0MQ wiring.
        int exchange = w.CreateExchange("EL", Zmq.SCOPE_LOCAL, "",
                                        Zmq.STYLE_LOAD_BALANCING);

        w.CreateQueue("QL", Zmq.SCOPE_LOCAL, "",
                      Zmq.NO_LIMIT, Zmq.NO_LIMIT, Zmq.NO_SWAP);
        w.Bind("EL", "QG", null, null);
        w.Bind("EG", "QL", null, null);

        //  Create a message to send.
        byte[] outMessage = new byte[messageSize];

        //  Start measuring the time.
        System.Diagnostics.Stopwatch watch;
        watch = new Stopwatch();
        watch.Start();


        byte[] inMessage;
        int    type;

        //  Start sending messages.
        for (int i = 0; i < roundtripCount; i++)
        {
            w.Send(exchange, outMessage, true);
            w.Receive(out inMessage, out type, true);
            Debug.Assert(inMessage.Length == messageSize);
        }
        //  Stop measuring the time.
        watch.Stop();
        Int64 elapsedTime = watch.ElapsedTicks;

        //  Compute and print out the latency.
        double latency = (double)(elapsedTime) / roundtripCount / 2 *
                         1000000 / Stopwatch.Frequency;

        Console.Out.WriteLine("Your average latency is {0} [us]",
                              latency.ToString("f2"));

        System.Threading.Thread.Sleep(5000);
        w.Destroy();

        return(0);
    }