CPU use when Threads = 1 - WeOnlyDo Discussion board

CPU use when Threads = 1 (wodWebServer / wodWebServer.NET)

by mattw55, Saturday, October 29, 2016, 21:20 (541 days ago)


I'm using the DLL version of the WOD WebServer control as a COM control. It's working well, but my environment (VFP 9) seems to only support threading with the Threads value set to 1, where each client is on its own thread, but still coordinated by the main thread. It was fine, but I am noticing that the more clients that connect, the higher my CPU use is. Some of this is to be expected, but I need to find out a way to minimize this effect. Right now I have about 30 clients attached and my CPU use, on a 3 core 2.2 Ghz machine, is around 6-8%. I'm afraid that want scale as well as I will need it to.

In this application, my clients are connecting in a long polling scenario, where the server keeps the connection open for 45 minutes waiting to see if there are any external events that would require responding to the client. If there are events, it responds, disconnects the client, and the client immediately reconnects. It there aren't any events within 45 minutes, the server disconnects the client and the client immediately reconnects.

I think each thread must have a timed process that checks to see if it needs to respond. If I'm correct in that assumption, I would like to know if there is any way that I could increase the interval of that internal timer and thereby reduce the CPU impact of each thread.

Thanks for your advice,

CPU use when Threads = 1

by Jasmine, Sunday, October 30, 2016, 00:21 (541 days ago) @ mattw55

Hi Matt.

We don't have any timers (except for checking timeouts) so there's nothing to tweak in threads. We only respond to windows messages for each thread.

Why do you say you're unable to set Threads = 0? Why that fails?


CPU use when Threads = 1

by mattw55, Sunday, October 30, 2016, 02:35 (541 days ago) @ Jasmine

Hi Jasmine,

Yes, setting Threads=0 works with VFP, but as I understand it, that turns off threading all together. Wouldn't that block processing (for other clients) if one client connected and was not responded to for a long time? Setting Threads to 2 in this environment definitely does not work. Clients connected but are not responded to.


CPU use when Threads = 1

by Jasmine, Sunday, October 30, 2016, 07:15 (541 days ago) @ mattw55

HI Matt.

It will not block, since sockets work in async way. THey do the job when they have some traffic, and then they're idle waiting for new jobs.

You should try it out to see which one behaves better for you.


CPU use when Threads = 1

by mattw55, Sunday, October 30, 2016, 16:35 (540 days ago) @ Jasmine

Ok, thanks for clearing that up. I have tried it with Threads = 0 and it does seem to work fine. In this particular case, because there is minimal processing being done for each client, this may be a better option. Looking at the CPU impact of changing from using threads to not using them was minimal though, perhaps only a 1% difference over 30 connected clients. With that said, your explanation still helps, as I can rule out the problem being a timer issue in the threads.

Thanks for you help,