zeromq / netmq

A 100% native C# implementation of ZeroMQ for .NET
Other
2.97k stars 746 forks source link

Maximum concurrent connections? #188

Closed mirror222 closed 9 years ago

mirror222 commented 9 years ago

I was testing the maximum concurrent connections that the netmq can handle:


using System;
using NetMQ;
using System.Numerics;
using System.IO;
using System.Text;

namespace HelloWorld
{
    class Program
    {
        private static void Main(string[] args)
        {
            BufferPool.SetBufferManagerBufferPool(1024 * 1024 * 10, 1024);

            using (NetMQContext ctx = NetMQContext.Create())
            {
                ctx.MaxSockets = 6000;

                using (var server = ctx.CreateRouterSocket())
                {        

                    server.Options.RouterRawSocket = true;
                    server.Bind("tcp://*:5556");

                    while (true)
                    {
                        byte[] id = server.Receive();
                        string message = server.ReceiveString();
                         string response = "HTTP/1.0 200 OK\r\n" +
                                        "Content-Type: text/html; charset=utf-8\r\n" +
                                        "Server: Server" +                                        
                                         "\r\n\r\nTest";

                        server.SendMore(id).Send(response);      

                        //  Close connection to browser
                        server.SendMore(id).Send("");
                     //   System.Threading.Thread.Sleep(1);           
                    }
                }
            }
            Console.ReadLine();
        }       
    }
}

and run the test with siege:


siege.exe -c 150 -t10s http://127.0.0.1:5556/

I got a many connection errors while testing

Lifting the server siege...      done.

Transactions:                   1154 hits
Availability:                  82.43 %                -------------- THIS LINE
Elapsed time:                   9.79 secs
Data transferred:               0.01 MB
Response time:                  0.32 secs
Transaction rate:             117.88 trans/sec
Throughput:                     0.00 MB/sec
Concurrency:                   37.28
Successful transactions:        1163
Failed transactions:             246
Longest transaction:            0.54
Shortest transaction:           0.01

however, it works perfectly if I use 50 concurrent connections.

was i doing anything wrong? any reply will be greatly appreciated.

Thank you.

somdoron commented 9 years ago

Few comments:

  1. You don't need the max socket parameter, this is not for internal connection but for zeromq sockets.
  2. You can use the stream socket type instead of router.
  3. Try without the buffer manager, it is know for reducing throughput
  4. Are you using the master or nuget version?

I will run the test as well.

On Tue, Dec 16, 2014 at 1:12 PM, mirror222 notifications@github.com wrote:

I was testing the maximum concurrent connections that the netmq can handle:

using System; using NetMQ; using System.Numerics; using System.IO; using System.Text;

namespace HelloWorld { class Program { private static void Main(string[] args) { BufferPool.SetBufferManagerBufferPool(1024 * 1024 * 10, 1024);

        using (NetMQContext ctx = NetMQContext.Create())
        {
            ctx.MaxSockets = 6000;

            using (var server = ctx.CreateRouterSocket())
            {

                server.Options.RouterRawSocket = true;
                server.Bind("tcp://*:5556");

                while (true)
                {
                    byte[] id = server.Receive();
                    string message = server.ReceiveString();
                     string response = "HTTP/1.0 200 OK\r\n" +
                                    "Content-Type: text/html; charset=utf-8\r\n" +
                                    "Server: Server" +
                                     "\r\n\r\nTest";

                    server.SendMore(id).Send(response);

                    //  Close connection to browser
                    server.SendMore(id).Send("");
                 //   System.Threading.Thread.Sleep(1);
                }
            }
        }
        Console.ReadLine();
    }
}

}

and run the test with siege:

siege.exe -c 150 -t10s http://127.0.0.1:5556/

I got a many connection errors while testing

Lifting the server siege... done.

Transactions: 1154 hits Availability: 82.43 %

however, it works perfectly if I use 50 concurrent connections.

am i doing anything wrong? any reply will be greatly appreciated.

Thank you.

— Reply to this email directly or view it on GitHub https://github.com/zeromq/netmq/issues/188.

somdoron commented 9 years ago

I got this results:

Transactions: 2796 hits Availability: 99.86 %

On nuget version (I think master version can do better).

Are you running on release mode? does your visual studio attached to the running process?

On Tue, Dec 16, 2014 at 1:49 PM, Doron Somech somdoron@gmail.com wrote:

Few comments:

  1. You don't need the max socket parameter, this is not for internal connection but for zeromq sockets.
  2. You can use the stream socket type instead of router.
  3. Try without the buffer manager, it is know for reducing throughput
  4. Are you using the master or nuget version?

I will run the test as well.

On Tue, Dec 16, 2014 at 1:12 PM, mirror222 notifications@github.com wrote:

I was testing the maximum concurrent connections that the netmq can handle:

using System; using NetMQ; using System.Numerics; using System.IO; using System.Text;

namespace HelloWorld { class Program { private static void Main(string[] args) { BufferPool.SetBufferManagerBufferPool(1024 * 1024 * 10, 1024);

        using (NetMQContext ctx = NetMQContext.Create())
        {
            ctx.MaxSockets = 6000;

            using (var server = ctx.CreateRouterSocket())
            {

                server.Options.RouterRawSocket = true;
                server.Bind("tcp://*:5556");

                while (true)
                {
                    byte[] id = server.Receive();
                    string message = server.ReceiveString();
                     string response = "HTTP/1.0 200 OK\r\n" +
                                    "Content-Type: text/html; charset=utf-8\r\n" +
                                    "Server: Server" +
                                     "\r\n\r\nTest";

                    server.SendMore(id).Send(response);

                    //  Close connection to browser
                    server.SendMore(id).Send("");
                 //   System.Threading.Thread.Sleep(1);
                }
            }
        }
        Console.ReadLine();
    }
}

}

and run the test with siege:

siege.exe -c 150 -t10s http://127.0.0.1:5556/

I got a many connection errors while testing

Lifting the server siege... done.

Transactions: 1154 hits Availability: 82.43 %

however, it works perfectly if I use 50 concurrent connections.

am i doing anything wrong? any reply will be greatly appreciated.

Thank you.

— Reply to this email directly or view it on GitHub https://github.com/zeromq/netmq/issues/188.

mirror222 commented 9 years ago

thank you so much for your prompt reply. I tested with the master version and ran on release mode.

I think the success rate is depended on the computer's hardware environment. how do you think?

is there any other tips to increase the success rate?

cheers!

somdoron commented 9 years ago

Your http response seems a little wrong, try to change to:

"HTTP/1.0 200 OK\r\n" + "Content-Type: text/html; charset=utf-8\r\n" + "Content-Length: 4\r\n"+ "Connection: close\r\n"+ "Server: Server" + "\r\n\r\nTest";

also try not to close the socket and let the browser close it.

Let me know if it is better.

On Tue, Dec 16, 2014 at 3:27 PM, mirror222 notifications@github.com wrote:

thank you so much for your prompt reply. I tested with the master version and ran on release mode.

I think the success rate is depended on the computer's hardware environment. how do you think?

is there any other tips to increase the success rate?

cheers!

— Reply to this email directly or view it on GitHub https://github.com/zeromq/netmq/issues/188#issuecomment-67158923.

mirror222 commented 9 years ago

Here are the new results with a Q8300 2.5G + 3G Ram computer, compiled with VS2012

nuget version with release mode:

Transactions:                   1911 hits
Availability:                  85.24 %
Elapsed time:                 10.08 secs

master version with release mode, got this message about 5 seconds later

[error] socket: unable to connect sock.c:230: Address family not supported by protocol

and the siege halted

New codes:


 using (NetMQContext ctx = NetMQContext.Create())
            {
                //ctx.MaxSockets = 6000;
                using (var server = ctx.CreateStreamSocket())
                {
                   // server.Options.RouterRawSocket = true;
                    server.Bind("tcp://*:5556");
                    string response = "HTTP/1.0 200 OK\r\n" +
                                      "Content-Type: text/html;charset=utf-8\r\n" +
                                      "Content-Length: 4\r\n"+
                                      "Connection: close\r\n"+
                                      "Server: Server" +
                                      "\r\n\r\nTest";
                    byte[] buff = Encoding.UTF8.GetBytes(response);
                    while (true)
                    {
                        byte[] id = server.Receive();
                        string message = server.ReceiveString();
                        server.SendMore(id).Send(buff);
                        //  Close connection to browser
                        server.SendMore(id).Send("");                      
                    }
                }
            }
somdoron commented 9 years ago

My results:

Transactions: 2856 hits Availability: 99.90 % Elapsed time: 9.48 secs Data transferred: 0.01 MB Response time: 0.00 secs Transaction rate: 301.11 trans/sec Throughput: 0.00 MB/sec Concurrency: 0.39 Successful transactions: 2856 Failed transactions: 3 Longest transaction: 0.03 Shortest transaction: 0.00

Please note that the elapsed time is because this is what you specify on the command line.

Regarding the error, I'm also getting it but on 500 concurrent calls, I'm not sure it have anything to NetMQ. The tool is using select on windows which give poor performance, can you try native windows tool? or test it manually.

Anyway I think it is related to the machine...

On Tue, Dec 16, 2014 at 4:20 PM, mirror222 notifications@github.com wrote:

Here are the new results with a Q8300 2.5G + 3G Ram computer, compiled with VS2012

nuget version with release mode: Transactions: 1911 hits Availability: 85.24 % Elapsed time: 10.08 secs

get this message about 5 seconds later: [error] socket: unable to connect sock.c:230: Address family not supported by protocol

New codes:

using (NetMQContext ctx = NetMQContext.Create()) { //ctx.MaxSockets = 6000;

            using (var server = ctx.CreateStreamSocket())
            {

               // server.Options.RouterRawSocket = true;
                server.Bind("tcp://*:5556");

                string response = "HTTP/1.0 200 OK\r\n" +
                                  "Content-Type: text/html;charset=utf-8\r\n" +
                                  "Content-Length: 4\r\n"+
                                  "Connection: close\r\n"+
                                  "Server: Server" +
                                  "\r\n\r\nTest";

                byte[] buff = Encoding.UTF8.GetBytes(response);

                while (true)
                {
                    byte[] id = server.Receive();
                    string message = server.ReceiveString();

                    server.SendMore(id).Send(buff);

                    //  Close connection to browser
                    server.SendMore(id).Send("");
                }
            }
        }

— Reply to this email directly or view it on GitHub https://github.com/zeromq/netmq/issues/188#issuecomment-67165588.

mirror222 commented 9 years ago

after closed the network firewall, new results Transactions: 3330 hits Availability: 98.64 % Elapsed time: 9.16 secs Data transferred: 0.01 MB Response time: 0.01 secs Transaction rate: 363.58 trans/sec

will try a native windows tool tomorrow, thankyou.