Skip to content

Re-create Selector if we hit the epoll(..) jdk bug which leads to 100% c... - #565

Merged
normanmaurer merged 8 commits into
3from
jdk_epoll_bug_workaround
Aug 29, 2012
Merged

normanmaurer merged 8 commits into
3from
jdk_epoll_bug_workaround

Conversation

@normanmaurer

Copy link
Copy Markdown
Member

...pu load. This is just a workaround but helps to recover. See #327

…% cpu load. This is just a workaround but helps to recover. See #327
@normanmaurer

Copy link
Copy Markdown
Member Author

I think we should also do the same workaround for the boss thread of NioClientSocketChannel as this can also be effected. So it may be related to #535

@normanmaurer

Copy link
Copy Markdown
Member Author

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use System.nanoTime? Its much cheaper, and also have have SelectorUtil.SELECT_WAIT_TIME_NANOS.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it cheaper? Maybe something to learn for me ;)

Sent from my iPhone. Excuse any typos....

Am 26.08.2012 um 13:20 schrieb Shay Banon [email protected]:

In src/main/java/org/jboss/netty/channel/socket/nio/AbstractNioWorker.java:

@@ -220,7 +253,32 @@ public void run() {
}

         try {
  •            SelectorUtil.select(selector);
    
  •            long beforeSelect = System.currentTimeMillis();
    
    Why not use System.nanoTime? Its much cheaper, and also have have SelectorUtil.SELECT_WAIT_TIME_NANOS.

—
Reply to this email directly or view it on GitHub.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know (and I researched it a bit) System.nanoTime is cheaper OS call wise compared to System.currentTimeInMillis. Also, if you use nanoTime you get considerably better precision which is what you are after here (compute elapsed time).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read somwhere that System.nanoTime() is not really something you should rely on.
Let me try to remember where ;)

Beside that what you think of this workaround?
Sent from my iPhone. Excuse any typos....

Am 26.08.2012 um 13:54 schrieb Shay Banon [email protected]:

In src/main/java/org/jboss/netty/channel/socket/nio/AbstractNioWorker.java:

@@ -220,7 +253,32 @@ public void run() {
}

         try {
  •            SelectorUtil.select(selector);
    
  •            long beforeSelect = System.currentTimeMillis();
    
    As far as I know (and I researched it a bit) System.nanoTime is cheaper OS call wise compared to System.currentTimeInMillis. Also, if you use nanoTime you get considerably better precision which is what you are after here (compute elapsed time).

—
Reply to this email directly or view it on GitHub.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi there,

I'm bumping in because I'm very interested in this topic as I do a lot of
duration measurement on my own project.
From what I've read so far, nanoTime cost is much higher than
currentTimeMillis:
http://sharmaak.blogspot.fr/2012/08/systemnanotime-vs-systemcurrenttimemill.html

Cheers,

Stéphane

2012/8/26 Norman Maurer [email protected]

In src/main/java/org/jboss/netty/channel/socket/nio/AbstractNioWorker.java:

@@ -220,7 +253,32 @@ public void run() {
}

         try {
  •            SelectorUtil.select(selector);
    
  •            long beforeSelect = System.currentTimeMillis();
    

I read somwhere that System.nanoTime() is not really something you should
rely on. Let me try to remember where ;) Beside that what you think of this
workaround? Sent from my iPhone. Excuse any typos.... Am 26.08.2012 um
13:54 schrieb Shay Banon [email protected]:
… <#13962cfa73bb7d1c_>
In
src/main/java/org/jboss/netty/channel/socket/nio/AbstractNioWorker.java: >
@@ -220,7 +253,32 @@ public void run() { > } > > try { > -
SelectorUtil.select(selector); > + long beforeSelect =
System.currentTimeMillis(); As far as I know (and I researched it a bit)
System.nanoTime is cheaper OS call wise compared to
System.currentTimeInMillis. Also, if you use nanoTime you get considerably
better precision which is what you are after here (compute elapsed time). —
Reply to this email directly or view it on GitHub.

—
Reply to this email directly or view it on GitHubhttps://github.com//pull/565/files#r1460786.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would still prefer nanoTime because it resists from system date shift.
The perf difference is negligible IMHO.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the performance should not be the "key" point here as this should only be executed if we suspect the cpu bug here. So not quite often.. So If you guys thing nanoTime is the way to go I will be happy to change that ;)

I just would like to know what you think about the "workaround" in general ;)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok switched to System.nanoTime()… Any other comments ?

Am 26.08.2012 um 16:17 schrieb Trustin Lee [email protected]:

In src/main/java/org/jboss/netty/channel/socket/nio/AbstractNioWorker.java:

@@ -220,7 +253,32 @@ public void run() {
}

         try {
  •            SelectorUtil.select(selector);
    
  •            long beforeSelect = System.currentTimeMillis();
    
    I would still prefer nanoTime because it resists from system date shift. The perf difference is negligible IMHO.
    —
    Reply to this email directly or view it on GitHub.

@ghost ghost assigned normanmaurer Aug 26, 2012
@kimchy

kimchy commented Aug 27, 2012

Copy link
Copy Markdown

General note, seems like this is one that people were hit by (jetty, mina), and I agree, this can definitely explain the 100% usage in the client socket, so +1 on getting this in (with the mentioned changes on check against nanos), and applying it also for the client boss.

…eout to detect it to be more save. Thanks to @kimchy for spot this
@normanmaurer

Copy link
Copy Markdown
Member Author

@kimchy applied the changes you suggested. Thanks again for review :)

@normanmaurer

Copy link
Copy Markdown
Member Author

If noone raise any more concerns I will just go aead an merge this into 3 and master

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SELECT_TIMEOUT is in milliseconds, so to make it nanoseconds it should be multiplied by 1000000.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really need more sleep.. Let me fix this and merge in ;)

Sent from my iPhone. Excuse any typos....

Am 28.08.2012 um 11:22 schrieb Shay Banon [email protected]:

In src/main/java/org/jboss/netty/channel/socket/nio/SelectorUtil.java:

@@ -28,6 +28,9 @@

 static final int DEFAULT_IO_THREADS = Runtime.getRuntime().availableProcessors() * 2;
  • static final int SELECT_TIMEOUT = 10;
  • static final int SELECT_TIMEOUT_NANOS = SELECT_TIMEOUT * 1000;
    SELECT_TIMEOUT is in milliseconds, so to make it nanoseconds it should be multiplied by 1000000.

—
Reply to this email directly or view it on GitHub.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason why you call SelectionKey.cancel() twice?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope.. Let me fix this.

@normanmaurer

Copy link
Copy Markdown
Member Author

@trustin ok code adjusted to address your comments. I will merge it to 3 and master.. Thanks!

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

Successfully merging this pull request may close these issues.

4 participants