Re: [twsocket] IndexOf is slow when there are thousands of clientsconnected
Arno Garrels wrote: Fastream Technologies wrote: As far as I know, the TStringList-AddObject() method uses binary search for finding the correct index to insert when TStringList-Sorted = true. I don't know why I thought so but there is the method, Yes, it actually uses function QuickSort but that is still much slower than a simple Add() of an unsorted list. So in order to compare speed one has to messure both Add() and IndexOf(). In most cases IndexOf() is not used frequently if not just once when the client disconnects from the server. I uploaded my test binary here : http://www.duodata.de/misc/delphi/ics/Project1.zip That should make the problem clear. Increase the number and wait... -- Arno Garrels -- 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] IndexOf is slow when there are thousands of clientsconnected
Anton S. wrote: I dared to start the discussion in a separate thread. I have seen a bottleneck in ICS with tens of thousands of clients: When a client is disconnected the TWSocketServer calls FClientList-IndexOf() for finding the index to remove the object! IndexOf is simply exhaustive search and it is a huge CPU hog when there are 30k clients! In the one old internet component library implemented a hashed list to store sockets. Hash is computed as Integer(SocketHandle) div HashBase and in that position of the array the first socket object is stored with pointer to the next socket object having the same hash (simple one-d\irectional list). But I'm unsure whether this way is much better. In most cases IndexOf() is not used frequently if not just once when the client disconnects from the server. Doesn't it used in HTTP server every time response is sent? It happens pretty often. I don't think so, why should it? -- Arno Garrels -- 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] IndexOf is slow when there are thousands of clientsconnected
Arno wrote: I don't think so, why should it? Well, the connection to HTTP client is closed when response is sent (usually; there are some options in the request header to keep it but these cases are rarer). I'm just supposing, not asserting. -- Anton -- 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] IndexOf is slow when there are thousands of clientsconnected
Anton S. wrote: Arno wrote: I don't think so, why should it? Well, the connection to HTTP client is closed when response is sent That depends on whether the client uses HTTP 1.0 or HTTP 1.1 and whether or not the Keep-Alive header is sent. (usually; there are some options in the request header to keep it but these cases are rarer). I'm just supposing, not asserting. IndexOf() is only used when the client disconnects in order to delete its reference from the client list. -- Arno Garrels -- 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] IndexOf is slow when there are thousands of clientsconnected
So you are right in your saying that when Sorted = true, Add()'s are with binary search. But there is a HACK one needs to be very careful about: If you do not set Duplicates = dupAccept, then it calls IndexOf() before inserting to see if the same value exists!! That must have been the reason our code got that faster (not the to insert() change)! Regards, SZ On Tue, Dec 7, 2010 at 7:48 PM, Arno Garrels arno.garr...@gmx.de wrote: Anton S. wrote: Arno wrote: I don't think so, why should it? Well, the connection to HTTP client is closed when response is sent That depends on whether the client uses HTTP 1.0 or HTTP 1.1 and whether or not the Keep-Alive header is sent. (usually; there are some options in the request header to keep it but these cases are rarer). I'm just supposing, not asserting. IndexOf() is only used when the client disconnects in order to delete its reference from the client list. -- Arno Garrels -- 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