views:

46

answers:

4

hi, as i seen topic which not recommending more thn 200 threads for server machine,

i am trying to implement Listener class which listens 1000 devices, i mean 1000 devices sending different type of messages to that application,

i tried 2 different way 1. creat thread for each device runtime and dynamic list which hold the messages for that device and start thread for processing those messages from the list

but my machine not creating thread more thn 50 :), and i agree its bad idea...

  1. i created 10 different lists which holds the messages 10 different type of messages and i created 10 processor thread for those list, which go to its relevent list and proces the message and thn delete it....

but here is the problem, let say i recieved 50 messages from 50 devices in List 1 by the time its list1's processor thread will go to last message (50th) its time will be expired which is 10 second

any idea to for best architecture that talk to more thn 500 devices and process thier different type of messages with in 10 seconds..

THanks ASamad

+1  A: 

I think you need to partition the system differently. The listeners should be high priority but only enqueue the requests. The queue should then be processed using a pool of workers. You could add prioritisation and other optimisations on the dequeuing side. In terms of getting every process done in 10s you will really be getting the second half of the system optimised.

Think of the traditional queuing system. You have a queue of work requests to process. Each request has a series of attributes. Lets same Name (string) and Priority (int). Once a the work request has been queued, other worker (thread/processes etc) can interrogate the queue to pull out items based on priority and process them.

To get the 10s I'd say as soon a worker has started processing the request a timer comes in to play and will mark that request as timed out in 10s unless the worker completes the task. Other workers can watch for results of the work in the queue and then handle the response behaviours.

Preet Sangha
A: 

i am workign in C#, my application connected with the server as a client using tcp/ip, that server further connectes with online devices, sending messages to server with device id and message data and message typ thn further i recieving messages from that server and thn reply back throug that server using device id,

Thanks

Abdul Samad
A: 

Preet: Thanks for your reply, could you please more eloberate what do you mean by priortization and optimization, you mean shall i devide application into 2 part one is listener? and other is processor?

i am not very experienced programmer, just trying my best

THanks ASamad

Abdul Samad
please add comment to Preet's answer instead of adding a new answer by yourself.
EffoStaff Effo
A: 

use other Highly-concurrent programming models other than threaded, though threaded is one of the highly-concurrent models too.

if socket/tcpip/network messaging, please use epoll on Linux 2.6x and completion port on win/msvc.

see the docoument named EffoNetMsg.pdf at http://code.google.com/p/effonetmsg/downloads/list to learn more about highly-concurrent programming models. we only use 2 or 3 threads for multi-listeners and >1000 clients.

EffoStaff Effo