Re: [twsocket] multithread server
Hi Lukas, > version 1: incoming data are received in main thread and are written to > buffer of client, client has own thread to process data in buffer > version 2: data are received in client thread (in same way as in demo > thread application) Possible you have a trhead problem. Possible a thread is waiting for another. On the other hand you have told that OnDataAvailable is called in a closed loop. Please set wsoNoReceivedLoop to false. If OnDataAvailable is not called contunously the you are pretty sure that is the problem, because message pump is not running. BTW: wy do you need multiple threads? Doing so is maybe the course of your problem? If you only have 200 client TCP connections it is quite possible it can be handled in main thread -- mvg, Wilfried http://www.mestdagh.biz http://www.comfortsoftware.be http://www.expertsoftware.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] multithread server
> there are about 150 clients (in average) connected at the same > time. sometimes program hang after 15 minutes of running, sometimes > after several hours. I've had ICS servers running for several months without hanging, but not with as many clients. Is the client an ICS application, or something you can emulate in ICS, if so try a version making connecting 150 connections to the server so you can test in a debug environment. I did this to test the ICS FTP server using TSocketServer, a threaded TMagFtp client with 250 simultaneous FTP sessions listing and downloading multiple files at the same time. > I am not sure what does TIME_WAIT means For debugging, you can add my Internet Protocol Helper Component to your server, once a minute call IpHlpTCPTable for a list of TCP connections, which will show any still in TIME_WAIT, so see how quickly they are releasing memory, this is the same as using netstat. http://www.magsys.co.uk/delphi/magiphlp.asp Angus -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] multithread server
hi, thank for reply. there are about 150 clients (in average) connected at the same time. sometimes program hang after 15 minutes of running, sometimes after several hours. I think there is no memory problem because server has a lot of memory and when I check it using taskmanager there is a lot of free memory (service itself is consuming about 58 mb of RAM), procesor time of the process is below 1%. There are about 10 connection in TIME_WAIT state. Values are taken when service is running without problem, I will check it again when it will hang. I am not sure what does TIME_WAIT means - by googling I have found that it is closing socket waiting for final messages handshaking - is it true? I hope it is not my problem because if client is not active (1 minute) it is disconnected by the server. Is it possible that sockets which were not correctly disconnected (e.g. clients was disconnected from network) will stay in TIME_WAIT state? Even when server close them explicitly after communication timeout? Service is running on more servers and it seems to work fine with less clients. I have problem only on one server - unfortunatelly there is no chance to debug service (only write to log is possible). I will try to test in GUI application. I did some test and now I have 2 version: version 1: incoming data are received in main thread and are written to buffer of client, client has own thread to process data in buffer version 2: data are received in client thread (in same way as in demo thread application) It seems version 1 is more stable but it will hang too. Processing of data is done by the same procedures so I hope there is no difference. Lukas Dne 18.8.2011 11:26, Wilfried Mestdagh napsal(a): Hi, When receive returns -1 then it indicate an error, but you don't have to worry about it. If MultiThread is True then TWSocket uses his own message pump. You can use it yourself also or override it. If OnDataAvailable is called in a closed loop then there is something wrong with winsock. You tell that it happens after a while when many clients connecting (and disconnecting ???). Is this predictable? Is it possible you have many sockets in TIME_WAIT state or that you have run out of non-pagable memory? You can check the former with 'netstat -a'. The latter with task manager. Note that a socket uses 10kb (or more depeniding on traffic), that non-pagable memory is maximum 1/8 of total real memory (not virtual). Have you the same problem if you run the same application in a GUI or console application? You can set wsoNoReceivedLoop for each client then OnDataAvailable is not called in closed loop but with a message handler. Eventually more easy to debug? -- lukas skala envinet a.s. divize projektu a inzenyringu (project and engineering division) modrinova 1094 674 01 trebic tel: +420 568 409 862 (811) fax: +420 568 409 875 gsm: +420 724 461 062 icq: 66842878 eml: lukas.sk...@envinet.cz, luky.sk...@gmail.com www: http://envinet.cz -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] multithread server
Hi, When receive returns -1 then it indicate an error, but you don't have to worry about it. If MultiThread is True then TWSocket uses his own message pump. You can use it yourself also or override it. If OnDataAvailable is called in a closed loop then there is something wrong with winsock. You tell that it happens after a while when many clients connecting (and disconnecting ???). Is this predictable? Is it possible you have many sockets in TIME_WAIT state or that you have run out of non-pagable memory? You can check the former with 'netstat -a'. The latter with task manager. Note that a socket uses 10kb (or more depeniding on traffic), that non-pagable memory is maximum 1/8 of total real memory (not virtual). Have you the same problem if you run the same application in a GUI or console application? You can set wsoNoReceivedLoop for each client then OnDataAvailable is not called in closed loop but with a message handler. Eventually more easy to debug? -- mvg, Wilfried http://www.mestdagh.biz http://www.comfortsoftware.be http://www.expertsoftware.be > -Oorspronkelijk bericht- > Van: twsocket-boun...@elists.org [mailto:twsocket-boun...@elists.org] > Namens Lukáš Skála > Verzonden: donderdag 18 augustus 2011 8:05 > Aan: twsocket@elists.org > Onderwerp: Re: [twsocket] multithread server > > hi, > I always call Receive (even if RcvdCount returns zero). When RcvdCount > returns zero then Receive returns -1 value. Is it normal? > What is property Multithreaded in TWServerSocket? Should it be set to > TRUE? In demo application property is set to FALSE and only client > sockets are set to TRUE. > > Now I have no idea where is problem with service hanging. Any idea > where > to look is welcome. > Thanks > Lukas Skala > > > Dne 17.8.2011 18:18, Wilfried Mestdagh napsal(a): > > Hi, > > > > If OnDataAvailable triggers then you have to try to receive data, > even if RcvdCount (wich is unreliable) returns 0. If you don't receive > then OnDataAvailable will be called again in a closed loop en that is > probably what happens. > > > > > -- > lukas skala > envinet a.s. > divize projektu a inzenyringu (project and engineering division) > modrinova 1094 > 674 01 trebic > > tel: +420 568 409 862 (811) > fax: +420 568 409 875 > gsm: +420 724 461 062 > icq: 66842878 > eml: lukas.sk...@envinet.cz, luky.sk...@gmail.com > www: http://envinet.cz > > > > > -- > To unsubscribe or change your settings for TWSocket mailing list > please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket > Visit our website at http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] multithread server
hi, I always call Receive (even if RcvdCount returns zero). When RcvdCount returns zero then Receive returns -1 value. Is it normal? What is property Multithreaded in TWServerSocket? Should it be set to TRUE? In demo application property is set to FALSE and only client sockets are set to TRUE. Now I have no idea where is problem with service hanging. Any idea where to look is welcome. Thanks Lukas Skala Dne 17.8.2011 18:18, Wilfried Mestdagh napsal(a): Hi, If OnDataAvailable triggers then you have to try to receive data, even if RcvdCount (wich is unreliable) returns 0. If you don't receive then OnDataAvailable will be called again in a closed loop en that is probably what happens. -- lukas skala envinet a.s. divize projektu a inzenyringu (project and engineering division) modrinova 1094 674 01 trebic tel: +420 568 409 862 (811) fax: +420 568 409 875 gsm: +420 724 461 062 icq: 66842878 eml: lukas.sk...@envinet.cz, luky.sk...@gmail.com www: http://envinet.cz -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] multithread server
Hi, If OnDataAvailable triggers then you have to try to receive data, even if RcvdCount (wich is unreliable) returns 0. If you don't receive then OnDataAvailable will be called again in a closed loop en that is probably what happens. -- mvg, Wilfried http://www.mestdagh.biz http://www.comfortsoftware.be http://www.expertsoftware.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] multithread server
Sometimes Windows triggers OnDataAvailable when no data is actually available. This is how it works. It is safe to ignore it. The most important is to call Recv (or any derivative) anyway. Using RcvdCount to decide to call or no Recv is wrong. Always call Recv which is the only one to actually reset winsock internal flag. francois.pie...@overbyte.be The author of the freeware multi-tier middleware MidWare The author of the freeware Internet Component Suite (ICS) http://www.overbyte.be -Message d'origine- From: Lukas Skala Sent: Wednesday, August 17, 2011 4:01 PM To: twsocket@elists.org Subject: [twsocket] multithread server hello, I have tcp server (developed as Windows Service) based on OverbyteIcsThrdSrv1.pas demo. There is maximum of 200 clients. Server is hanging after some time of running - it is unable to connect any new client. I have added log in all events of TWSocketServer (оn events start line and events end line). So I know that program is not hanging in any events. I have some timer in service also and operation inside OnTimer events are also logged. When server is hanged timer event is no more triggered - it seems that main thread is very busy by triggering OnClientDataAvailable - but in fact no data are incoming, function RcvdCount in OnClientDataAvailable events returns zero and function Receive returns -1 length (see part of log below please). Please what does it means (why is this event triggered when no data are incoming?) and how to avoid this behaviour? 17.08.11 15:42:52 I ClientDataAvailable started. 17.08.11 15:42:52 I Received from 89.24.4.161: 0 byte(s). 17.08.11 15:42:52 D Received -1 byte(s). 17.08.11 15:42:52 I ClientDataAvailable ended. Thanks for any idea. Lukas -- lukas skala envinet a.s. divize projektu a inzenyringu (project and engineering division) modrinova 1094 674 01 trebic tel: +420 568 409 862 (811) fax: +420 568 409 875 gsm: +420 724 461 062 icq: 66842878 eml: lukas.sk...@envinet.cz, luky.sk...@gmail.com www: http://envinet.cz -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
[twsocket] multithread server
hello, I have tcp server (developed as Windows Service) based on OverbyteIcsThrdSrv1.pas demo. There is maximum of 200 clients. Server is hanging after some time of running - it is unable to connect any new client. I have added log in all events of TWSocketServer (оn events start line and events end line). So I know that program is not hanging in any events. I have some timer in service also and operation inside OnTimer events are also logged. When server is hanged timer event is no more triggered - it seems that main thread is very busy by triggering OnClientDataAvailable - but in fact no data are incoming, function RcvdCount in OnClientDataAvailable events returns zero and function Receive returns -1 length (see part of log below please). Please what does it means (why is this event triggered when no data are incoming?) and how to avoid this behaviour? 17.08.11 15:42:52 I ClientDataAvailable started. 17.08.11 15:42:52 I Received from 89.24.4.161: 0 byte(s). 17.08.11 15:42:52 D Received -1 byte(s). 17.08.11 15:42:52 I ClientDataAvailable ended. Thanks for any idea. Lukas -- lukas skala envinet a.s. divize projektu a inzenyringu (project and engineering division) modrinova 1094 674 01 trebic tel: +420 568 409 862 (811) fax: +420 568 409 875 gsm: +420 724 461 062 icq: 66842878 eml: lukas.sk...@envinet.cz, luky.sk...@gmail.com www: http://envinet.cz -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be