Click here to Skip to main content
15,881,812 members
Home / Discussions / C#
   

C#

 
GeneralRe: c# serial port Pin
Garth J Lancaster17-Dec-09 11:36
professionalGarth J Lancaster17-Dec-09 11:36 
GeneralRe: c# serial port Pin
aniarun17-Dec-09 12:10
aniarun17-Dec-09 12:10 
GeneralRe: c# serial port Pin
Roger Wright17-Dec-09 18:57
professionalRoger Wright17-Dec-09 18:57 
GeneralRe: c# serial port Pin
aniarun20-Dec-09 12:28
aniarun20-Dec-09 12:28 
GeneralRe: c# serial port Pin
Roger Wright20-Dec-09 13:46
professionalRoger Wright20-Dec-09 13:46 
QuestionWeb Service Object References Pin
RacerNerd17-Dec-09 9:09
RacerNerd17-Dec-09 9:09 
AnswerRe: Web Service Object References Pin
Abhinav S17-Dec-09 17:07
Abhinav S17-Dec-09 17:07 
QuestionHigh Load Asynchronous TCP Server & Client Discussion Pin
Harvey Saayman17-Dec-09 8:41
Harvey Saayman17-Dec-09 8:41 
Hey guys

I had this at the quick answers section but I'm moving it here cause this is more of a discussion than a particular problem.

I've only recently started looking at the .Net asynchronous programming model and I feel that I more or less get the concept. I've started throwing together a server & client that works more or less... But stress testing it yielded very strange results. I think there's something to this asynchronous model that I don't see

By stress testing I mean I have a single client(when this works I'll do the same with multiple clients) that sends plain text messages in an infinite loop. The loop has a counter so each message looks like this: 1: My plain text message \r\n[char 3], [char 3] being the packet terminator.

I have a 2nd client that receives the messages and just appends them to a TextBox.

Notes: 
0) I am using TCP so the packages are guaranteed, right?
1) The server, for now, is just an echo server... I takes a message and sends it to every 
   connected client except the one it originated from
2) All 3 apps are done using the asynchronous model


Now when I run all these apps I get very strange results as mentioned before. I see packet 1, 2, 3, 27, 127. Then much later on ill see packet 9 appearing after packet 20000 for example. Some packets are missing characters and some are repeated several times. Quite often the client moans that the server forcibly closed the connection...

Nagy Vilmos answered my quick answers question and said

Nagy Vilmos wrote:
If you are expecting high volume then the first thing to do is make sure your receiver takes the data off the inbound queue PDQ and puts it onto a call stack that you manage on a different thread.

A regular mistake is to process data directly from the TCP/IP pipe and expext the world to be sunny.


I really hope he sees this cause I'd like to pick his brain! But if not perhaps someone else can clarify...

By make sure your receiver takes the data off the inbound queue PDQ and puts it onto a call stack that you manage on a different thread I think he means to NOT process the data in the DataReceivedCallBack... Which makes sense I guess, cause while im processing a piece of data, 20 other pieces arrived and somewhere along the line something HAS to give in... can someone confirm this assumption?

He also mentions to put it in a call stack and process it on a different thread... So I'm assuming he means to just dump it in some variable to get it out of the read buffers as not to clog them and process it later... can someone confirm this assumption? An example would be nice, and I'm after efficiency, this server and the client code needs to be very scalable so please bare that in mind.

Another thing I was pondering was the read buffer sizes... How big do i make them? As far as i can see a small buffer would maybe need to make 5 or 6 callbacks(for arguments sake) for a single packet and callbacks are expensive so performance is lost. A Big buffer wont be fully utilized so alot of ram will be wasted. So the sweet spot would be to figure out how big your largest packet might be and make the read buffer that size...Once again I'm assuming all of this so if someone could confirm it that would rock.

I've googled high load tcp servers & clients in C# but I cant seem to find an article that explains it completely... Most of the time it just explain the .Net asynchronous programming model.

If someone could share some knowledge, experiences, tips, links to good articles or anything i would be really greatful. I really want to understand this and not just copy and paste some code.

Thanks for taking the time to read this, if you read this far you r0ck \m/ Smile | :)

Harvey Saayman - South Africa
Software Developer
.Net, C#, SQL

you.suck = (you.Occupation == jobTitles.Programmer && you.Passion != Programming)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111

QuestionMicrosoft Reporting (subreports) Pin
kruegersck17-Dec-09 8:09
kruegersck17-Dec-09 8:09 
QuestionTrying to retrieve a variable from a program Pin
JTRizos17-Dec-09 6:38
JTRizos17-Dec-09 6:38 
AnswerRe: Trying to retrieve a variable from a program Pin
ricmil4217-Dec-09 6:49
ricmil4217-Dec-09 6:49 
GeneralRe: Trying to retrieve a variable from a program Pin
JTRizos17-Dec-09 7:11
JTRizos17-Dec-09 7:11 
GeneralRe: Trying to retrieve a variable from a program Pin
ricmil4217-Dec-09 7:27
ricmil4217-Dec-09 7:27 
GeneralRe: Trying to retrieve a variable from a program Pin
JTRizos17-Dec-09 8:34
JTRizos17-Dec-09 8:34 
GeneralRe: Trying to retrieve a variable from a program Pin
ricmil4217-Dec-09 8:39
ricmil4217-Dec-09 8:39 
GeneralRe: Trying to retrieve a variable from a program Pin
JTRizos17-Dec-09 8:48
JTRizos17-Dec-09 8:48 
AnswerRe: Trying to retrieve a variable from a program Pin
Alan N17-Dec-09 9:12
Alan N17-Dec-09 9:12 
AnswerRe: Trying to retrieve a variable from a program Pin
JTRizos17-Dec-09 9:43
JTRizos17-Dec-09 9:43 
QuestionPropertyGrid usage Pin
rbuchana17-Dec-09 5:30
rbuchana17-Dec-09 5:30 
AnswerRe: PropertyGrid usage Pin
Dr.Walt Fair, PE17-Dec-09 5:50
professionalDr.Walt Fair, PE17-Dec-09 5:50 
GeneralRe: PropertyGrid usage Pin
rbuchana17-Dec-09 6:14
rbuchana17-Dec-09 6:14 
GeneralRe: PropertyGrid usage Pin
Dr.Walt Fair, PE17-Dec-09 7:09
professionalDr.Walt Fair, PE17-Dec-09 7:09 
GeneralRe: PropertyGrid usage Pin
rbuchana17-Dec-09 7:09
rbuchana17-Dec-09 7:09 
QuestionAutomate Web Browser control in Multiple Threads Pin
Sumit_Ghosh17-Dec-09 4:56
Sumit_Ghosh17-Dec-09 4:56 
AnswerRe: Automate Web Browser control in Multiple Threads Pin
Dave Kreskowiak17-Dec-09 10:59
mveDave Kreskowiak17-Dec-09 10:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.