<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Feb 17, 2015 at 7:03 AM, Michael Van Canneyt <span dir="ltr"><<a href="mailto:michael@freepascal.org" target="_blank">michael@freepascal.org</a>></span> wrote:<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span>
On Mon, 16 Feb 2015, silvioprog wrote:<br>
</span><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span>
On Mon, Feb 16, 2015 at 7:23 AM, Michael Van Canneyt <<a href="mailto:michael@freepascal.org" target="_blank">michael@freepascal.org</a>> wrote:<br></span><span>
Good.<br>
<br>
But I don't know it we need two arrays, I think that a hash list will suit well, I'll explain it below ...<br>
<br>
- New Request comes in. - No thread to handle request is available in pool.<br>
- Request is accepted and put in incoming requestsarray.<br>
- Check outgoing response array, send back any responses.<br>
- When Thread finishes a request, puts it in outgoing responses array.<br>
<br>
Details will depend heavily on the way the pool is handled.<br>
<br>
<br>
... I don't know if you tested the code that I sent you, but I've already done it, and in an unique array. =) The implemented structure works this way:<br>
<br>
- the main acceptconn waits the first request;<br>
- after receiving the first request, the execution comes from the main acceptconn, creating a new thread, that has an own acceptconn;<br>
- the first open thread keep waiting for new requests in its own acceptconn, keeping the main acceptconn in 'stand-by'.<br>
<br>
If an user make two or more later requests, it will call the acceptconn from the thread, and the main acceptconn will go on in stand-by. If a thread get in a long<br>
process (e.g: that 10 seconds loop), the main acceptconn it will call, that leaving from the stand-by status, creating a new thread, putting this new processing on<br>
it.<br>
</span></blockquote>
<br>
I will check your code.</blockquote><div><br></div><div>Good! =)</div><div><br></div><div>After that I'll start the changes directly in custfcgi.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span>
In short, if a request is short, only one thread is created and one acceptconn is used; if a new request takes some time to be processed, the application opens a<br>
new thread to process the other requests.<br>
<br></span>
Another thing: IMHO, it is interesting to use hash lists instead of commom arrays. A hash list has a internal generic array.<br>
</blockquote>
<br>
First of all, your sample code is simply wrong.<br></blockquote><div><br></div><div>You are right.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
The threadlist is faster than the hashlist.<br>
<br>
Change your code so that you a) Set the capacity of the list.<br>
b) add the items to the LIST, not the CommomList:<br>
<br>
CommomList := TThreadList.Create;<br>
try<br>
List := CommomList.LockList; //<br>
List.Capacity:=Count+1;<br>
for I := 1 to Count do<br>
begin<br>
Item := TFCGIThread.Create;<br>
Item.Name := 'thread_' + IntToStr(I);<br>
List.Add(Item); // adding to LIST not COMMOMLIST<br>
end;<br>
CommomList.UnlockList; // unlock<br>
<br>
If you do that, you'll see that the list is about 30% faster.<br>
<br>
home: >./mytest<br>
Hash: 00:00:00.752 vs Common: 00:00:00.526<br>
So an ordinary (common) list is faster.<br></blockquote><div><br></div><div>Really, you are right! I made a confusion, because in other languages, most of the time, HashSet() is more fast than ArrayList(). In Pascal it seems a bit different (I need to do more tests after).</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Then: when you do such tests, you must do 2 test runs, with the order of the tests reversed.<br>
The first of your 2 tests must always ask memory from the OS, because none is allocated yet. The second can re-use the memory and thus will be faster, this creates a skew in the result.<br></blockquote><div><br></div><div>Yes. I'll do it.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
But then: where do you want to use a hash list ?<br></blockquote><div><br></div><div>I don't want to use it anymore. Because you showed that an ordinary TFPList is more fast than a THashSet.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
I don't believe that iterating over a hashlist is very useful, for that you can use a list.<br>
<br>
A hashlist is only useful if you need to do lookups based on a key. So what do you want to look up ?<br>
Threads ? I don't think that creating 150000 threads is a very realistic example. I'm not sure the OS can pull this :)<br>
So, if you have 100 threads, this will be more than enough, and to use a hash list for 100 items seems a bit overkill.<br>
Maybe I am missing something ?<br>
<br>
But if you still, after all this, want to use a hashlist: use one from contnrs.pp, not the generics one.</blockquote></div><div><br></div><div>In this case, we could use a RTL ThreadList. Now I understand the internal code (it is very simple), so I can use it correctly.</div><div><br></div><div>I'll wait you check my last changes in "FastCGI_Proxy_nginx_Apache24_III.zip", so, after that, I'll go back to the implementations directly in custfcgi, now using ThreadList. =)</div><div><br></div>--<br><div>Silvio Clécio<br>My public projects - <a href="http://github.com/silvioprog" target="_blank">github.com/silvioprog</a></div>
</div></div>