joswa / mongoose

Automatically exported from code.google.com/p/mongoose
MIT License
0 stars 0 forks source link

CPU usage reach 99% for a prolong time when terminate #171

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Use WinXP command prompt to start mongoose, 'mongoose -r ".\root"
2. then press Ctrl+C to terminate the program
3. mongoose process cpu usage will reach 99% for a very long time, need use 
process manager to terminate it

What is the expected output? What do you see instead?
Expect the mongoose process to gracefully terminated within seconds (behaviour 
in 2.8).
The mongoose (2.9) just print out "Exiting on signal 2, waiting for all threads 
to finish...", but never terminated.

What version of the product are you using? On what operating system?
Upgrade from 2.8 to 2.9
Windows XP with SP3 English

Please provide any additional information below.
No client has been connected to the server, just start then terminate it.

Original issue reported on code.google.com by mira...@gmail.com on 6 Sep 2010 at 3:05

GoogleCodeExporter commented 9 years ago
Bug confirmed. Only happens for Ctrl+c as described. Note: in Windows, no need 
to wait for child threads to close. Linux may differ.

Original comment by googl...@springtimesoftware.com on 10 Sep 2010 at 5:34

GoogleCodeExporter commented 9 years ago
Is that been fixed in the mongoose-latest.exe?

Thanks.

Original comment by mira...@gmail.com on 11 Sep 2010 at 8:58

GoogleCodeExporter commented 9 years ago
Short answer: yes, it has been fixed.

Long answer: it was kind of fixed. The root cause of 100% CPU was this:
  when termination signal is received, master thread sends a broadcast notification to
  all worker threads to exit, and waits until all worker threads exit.
  For notification, a pthread_cond_broadcast() function is used,
  which works fine on UNIX but is badly implemented by me on Windows.
  Basically, worker threads do not receive notification and continue
  to run, leaving master thread blocked forever.

Latest version of executable just exist the application without waiting for all
worker threads to exit. This is fine for standalone application, but if somebody
embeds mongoose, mg_stop() call will still block forever.

Original comment by valenok on 11 Sep 2010 at 9:10

GoogleCodeExporter commented 9 years ago
This is now fixed, 2.10 is released.

Original comment by valenok on 12 Sep 2010 at 9:28

GoogleCodeExporter commented 9 years ago
I think you have changed the behaviour of 2.10. As I start mongoose in the 
command prompt, there will be nothing shown in the console as 2.8/2.9, instead 
a tray icon is started.

When pressing ctrl+C in the command prompt console, there will be nothing 
happened and I need to use the tray icon to stop mongoose.

So I cannot confirm whether the issue is being fixed.

BTW, is there any way to not using the tray icon and revert back to the same 
behaviour as 2.8/2.9 so that I can test with the issue?

Original comment by mira...@gmail.com on 14 Sep 2010 at 2:07

GoogleCodeExporter commented 9 years ago
I have been wanting a tray icon instead of a console for a long time. But I can 
also see that some people would want a console.

We don't want to keep adding features to Mongoose because we want it to be 
tiny. So why not consider conditional compilation? It is possible to automate 
many different versions of a product, using conditional compilation. One single 
Make file can generate many different executables, each one tiny, but each one 
having different features. The user can then download the executable version 
they want (or compile it themselves, for embedded applications).

I'm still hoping to figure out some way each feature can be in a separate 
binary file, yet be called by a kernel file. I don't want it to be as 
complicated as DLLs because they have a lot of overhead.

Original comment by googl...@springtimesoftware.com on 14 Sep 2010 at 3:06

GoogleCodeExporter commented 9 years ago
The 99% issue is fixed because in the code calls PostQuitMessage() after 
mg_stop() (it was not calling mg_stop() at all when I commented on 11 Sept). So 
if mg_stop() hangs, application would hang as well, leaving tray icon on the 
system tray forever.

As to multiple options: of course conditional compilation is possible. In fact, 
Mongoose currently has conditional compilation for the following:
DEBUG - produce lots of noisy debug messages, useful for debugging
NO_SSL_DL - do not load SSL libraries dynamically, link against them at compile 
time
NO_CGI - disable CGI
_WIN32_WCE - include support for WinCE
NO_SSL - disable SSL completely

There 5 conditionals. Simple math says that there are sum_from_0_to_5(n!/k!(n - 
k)!) = 2^n, where n is the number of conditionals. It is 2^5 = 32.

It is now 32 possible mongoose builds - with or without SSL, debug, CGI, 
etcetera. Each new conditional doubles the number of possible builds. Say, if I 
add console support conditional, it'll be 64 possible builds. Do I want to have 
all these possibilities actually built and make available to download? No. It 
will be frustrating, not helpful. And don't forget the .dll file - for those 
who uses Mongoose in embedded mode on Windows, DLL is essential, not EXE. This 
again doubles the number.

Therefore, it makes sense to create only single executable for download with 
most common functionality. For me it means with all possible functionality. 
People that have different needs are special enough to take the sources and 
build stuff themselves, which is not a trivial task in non-developer-friendly 
Windows environment.

I believe most Windows users prefer tray icon version. So I made it this way.

Original comment by valenok on 14 Sep 2010 at 6:31