Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CPU100% on Windows Server 2012 #27

Closed
okahashi117 opened this issue Apr 4, 2014 · 20 comments
Closed

CPU100% on Windows Server 2012 #27

okahashi117 opened this issue Apr 4, 2014 · 20 comments

Comments

@okahashi117
Copy link

I got a problem with version 1.2.1.
CPU Usage becomes 100% on Widows Server 2012, Ruby version is 1.9.3 p545
Please try this code.

require 'cool.io'
ADDR = '127.0.0.1'
PORT = 4321
cool.io.server ADDR, PORT do
end
cool.io.run
@repeatedly
Copy link
Contributor

I want to know the problem is Cool.io or libev.
Could you try following code with libev 4.15?

http://codefundas.blogspot.jp/2010/09/create-tcp-echo-server-using-libev.html

@repeatedly
Copy link
Contributor

And it happens only on Widows Server 2012?
What about other Windows versions?

@okahashi117
Copy link
Author

What about other Windows versions?

CPU Usage value is different, but think it is the same problem. I will check more.

@okahashi117
Copy link
Author

I want to know the problem is Cool.io or libev.
Could you try following code with libev 4.15?

http://codefundas.blogspot.jp/2010/09/create-tcp-echo-server-using-libev.html

Anybody has a help to use libev on Windows ?

@repeatedly
Copy link
Contributor

Building libev with make failed?

@okahashi117
Copy link
Author

I've done it now, forget it, thank you.
but process will terminate in ev_io_start().

http://codefundas.blogspot.jp/2010/09/create-tcp-echo-server-using-libev.html

I will continue to check on ev.c.

@repeatedly
Copy link
Contributor

@okahashi117 It means above code doesn't work on Windows corretly with libev 4.15, right?

On my Mac, the result is below(I fixed some #include for Mac manner).
Server side:

$ gcc -L. -lev test_code.c
% ./a.out
Successfully connected with client.
1 client(s) connected.
message:hoge
message:foo
message:hoge
peer might closing: Undefined error: 0
0 client(s) connected.

Client side:

% gcc -o client test_code_client.c
% ./client
warning: this program uses gets(), which is unsafe.
hoge
message: hoge
foo
message: foo
hoge
message: hoge

@okahashi117
Copy link
Author

Hi,

It means above code doesn't work on Windows corretly with libev 4.15, right?

I'm not sure because I might me making a mistaken. I'm not familiar with gcc so much, you know, and some changes to were required to build the sample code you suggeseted, especially to use WinSock.
I want to check a little more.

@okahashi117
Copy link
Author

Ah?
I'm using mingw to compile on Windows. Is it correct? Should use cygwin ?

@repeatedly
Copy link
Contributor

some changes to were required to build the sample code you suggeseted, especially to use WinSock.

Ah, I see.

Should use cygwin ?

No, MinGW is correct. I also compile Cool.io with MinGW for windows binary.

@okahashi117
Copy link
Author

@repeatedly Do I need some option to compile libev correctly ?
I did just 'configure --prefix=/xxxx' and 'make'.
ev_default_loop(0) always returns Null and it makes a process crash, because ev_io_start() needs a valid loop pointer to realloc memory and shows segmentation fault.

@repeatedly
Copy link
Contributor

@okahashi117 Hmm... how about use ev_loop_new(0) instead of ev_default_loop(0)?

@okahashi117
Copy link
Author

@repeatedly
Same result I got.
I found that all backend flags were off (PORT, KQUEUE, EPOLL, POLL and SELECT) so that a loop pointer is always NULL.
I may be mistaken. Could you give me any help, please.

@repeatedly
Copy link
Contributor

@okahashi117 Hmm. On Windows, libev should use select.
How about define EV_USE_SELECT like -DEV_USE_SELECT?

@okahashi117
Copy link
Author

OK, HAVE_SELECT and HAVE_SYS_SELECT_H has been required.
But a process still terminates. I check more.

@okahashi117
Copy link
Author

@repeatedly Hi.
I built the program and tested.
'CPU100%' does not occur (0%-15%, Win2012R2, Win8, Win7).
So it seems it is a problem of Coolio or Ruby.

@repeatedly
Copy link
Contributor

@okahashi117 Okay.
And could you try following combination?

  • Using Cool.io 1.2.2 and set timeout to run method. 0.5 or similar timeout.
  • Another Ruby version, e.g. 2.0, 2.1.

I'm not familiar with Windows debug tools.
Do you find the code block which consumes CPU 100%?

@okahashi117
Copy link
Author

Same problem occurs with Cool.io 1.2.2

@repeatedly
Copy link
Contributor

From @okahashi117 , select seems to receive bad file descriptor and retry causes busy loop.
We investigate the problem deeply.

@repeatedly
Copy link
Contributor

My investigation is here:

The problem is fd to handle conversion (Use _get_osfhandle).

https://github.com/tarcieri/cool.io/blob/64657d653cafe2ed1c02f4ba38c347e6b9faf2b9/ext/libev/ev_select.c#L80

For example, if fd is 3, then handle is 352 or similar value.
In this result, FD_SET and FD_ISSET are broken.
Set handle using FD_SET(handle, vec_ri) but FD_ISSET(handle, vec_ri) failed.
I am not familiar with Windows these utilities implementation (Increase FD_SETSIZE doesn't help).

Second, I tried to use fd instead of handle directly.
It works on first access but select returns an error on next access.
I'm not sure why first select call succeeded.
TCPSocket creates fd using socket function in Ruby. Using this fd for select is invalid?

Other status.
Disabling EV_SELECT_USE_FD_SET doesn't help.
ev related values are same on between Windows and Mac, e.g. vec_ri, fd_count and etc.

There are several approaches to resolve this issue:

  • Research windows deeply for resolving first and second case. Maybe, need Windows expert.
  • Use Ruby's select for Windows. I'm not sure how effect other stat and timer watchers.
  • Implement JRuby extension

repeatedly added a commit that referenced this issue Apr 25, 2014
Avoid Ruby and Windows FD utilities conflict to fix #27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants