Thursday 15 September 2011

c# - to multi-thread or not on a scalable client-server application -


A few years ago I developed a server app (C #, .NET 4.0), which included many customers who connected it. The way I did this was to create a thread for each single connection and maintain a list of these connections. When I tested the app, he handled the connection to 50 customers across the country. And ran away from it (what I saw) right?

My questions are:

  1. For a scalable solution, multiple connections should be handled by different clients, or should I handle all the connections on a single thread?
  2. Is there a limit on the number of threads and threads normally on the net?
  3. What are the downsides to use threads in the net?

    I know that this is unclear, but since some time before I developed this project, I forgot some more complex details. I am interested in developing a scalable solution for a server application in .NET and if I want to know from the beginning of the areas of improvement in my view before it.

    UPDATE 1

    I did not use Thread Polling Instified. I have actually created a thread for a method (this is called method thread life)

    In Thread Life I had a while (true) statement in which I sent messages from the client Was waiting for Send me a message as long as I wait for the client (so long as I did not receive any message)

    In my application, the connections were fairly stable (i.e. customer long time Stay connected to the period of time) Therefore the connection was kept alive until the disconnection of the customer (after every message the connection was not closed, I will receive the message many times that I Status points)

    thread-per-connection is not a scalable solution.

    To scale well, you should use asynchronous socket methods specifically, the question is whether to multiplex them on the same thread or use the thread pool. Thread pool is better than multiplexing, but multi-level complications are introduced in it.

    Many devs try to learn socket programming and multithreading at the same time, which is still very high.

No comments:

Post a Comment