-
-
Notifications
You must be signed in to change notification settings - Fork 16.1k
Question of ioRatio in NioEventLoop and two backed array in SelectedSelectionKeySet #6058
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
Comments
This provides a rough mechanism to control how much time is spent processing IO related tasks (socket reads, connects, closed, hangups, etc..) vs "non-IO" related tasks. The "non-IO" tasks are
Some of the methods may return "invalid values" if we are operating on the internal array (e.g. Also I wonder if the iteration to bounds in // to call the updated method:
int size = selectedKeys.size();
processSelectedKeysOptimized(selectedKeys.flip(), size);
// alternatively if we make the changes suggested in this issue:
// processSelectedKeysOptimized(selectedKeys.array(), selectedKeys.size());
private void processSelectedKeysOptimized(SelectionKey[] selectedKeys, int size) {
for (int i = 0; i < size; ++i) {
final SelectionKey k = selectedKeys[i];
// null out entry in the array to allow to have it GC'ed once the Channel close
// See https://github.com/netty/netty/issues/2363
selectedKeys[i] = null;
...
if (needsToSelectAgain) {
for (int x = i + 1; x < size; ++x) {
selectedKeys[x] = null;
}
...
// Note we would have to be careful to always call end() before we select
selectedKeys = selectedKeys.end()
selectAgain();
size = selectedKeys.size();
i = -1;
}
}
} |
let me take a stab at this... |
@Scottmitch thank you for eliminating my doubts, this is my first time to create an issue in github. I am so happy for receiving your reply^^ |
Motivation: SelectedSelectionKeySet currently uses 2 arrays internally and users are expected to call flip() to access the underlying array and switch the active array. However we do not concurrently use 2 arrays at the same time and we can get away with using a single array if we are careful about when we reset the elements of the array. Modifications: - Introduce SelectedSelectionKeySetSelector which wraps a Selector and ensures we reset the underlying SelectedSelectionKeySet data structures before we select - The loop bounds in NioEventLoop#processSelectedKeysOptimized can be defined more precisely because we know the real size of the underlying array Result: Fixes netty#6058
Motivation: SelectedSelectionKeySet currently uses 2 arrays internally and users are expected to call flip() to access the underlying array and switch the active array. However we do not concurrently use 2 arrays at the same time and we can get away with using a single array if we are careful about when we reset the elements of the array. Modifications: - Introduce SelectedSelectionKeySetSelector which wraps a Selector and ensures we reset the underlying SelectedSelectionKeySet data structures before we select - The loop bounds in NioEventLoop#processSelectedKeysOptimized can be defined more precisely because we know the real size of the underlying array Result: Fixes netty#6058
Motivation: SelectedSelectionKeySet currently uses 2 arrays internally and users are expected to call flip() to access the underlying array and switch the active array. However we do not concurrently use 2 arrays at the same time and we can get away with using a single array if we are careful about when we reset the elements of the array. Modifications: - Introduce SelectedSelectionKeySetSelector which wraps a Selector and ensures we reset the underlying SelectedSelectionKeySet data structures before we select - The loop bounds in NioEventLoop#processSelectedKeysOptimized can be defined more precisely because we know the real size of the underlying array Result: Fixes #6058
Motivation: SelectedSelectionKeySet currently uses 2 arrays internally and users are expected to call flip() to access the underlying array and switch the active array. However we do not concurrently use 2 arrays at the same time and we can get away with using a single array if we are careful about when we reset the elements of the array. Modifications: - Introduce SelectedSelectionKeySetSelector which wraps a Selector and ensures we reset the underlying SelectedSelectionKeySet data structures before we select - The loop bounds in NioEventLoop#processSelectedKeysOptimized can be defined more precisely because we know the real size of the underlying array Result: Fixes netty#6058
还是不太明白ioRatio 到底是什么作用,能给解释下吗 |
@lxchinesszz - can you translate to English please? |
@Scottmitch He means that he does not understand the purpose of this parameter ioRatio. And I just read about what you wrote before, so I translate it into Chinese and replay to him.
这个参数提供了一个粗略的机制,用来大致控制处理IO相关(socket 读,链接,关闭,挂起等)和非IO相关任务的时间分配比.非IO任务是,由于使用Executor接口,例如Executor#execute(..),而在EventLoopGroup队列中的Runnable对象.参数值越小,越多的时间将消耗在非IO任务上.当前,100将禁止所有超时时间(详见源码runAllTasks(long timeoutNanos))并运行所有等待着的非IO任务. |
thanks @jiakme |
Motivation: SelectedSelectionKeySet currently uses 2 arrays internally and users are expected to call flip() to access the underlying array and switch the active array. However we do not concurrently use 2 arrays at the same time and we can get away with using a single array if we are careful about when we reset the elements of the array. Modifications: - Introduce SelectedSelectionKeySetSelector which wraps a Selector and ensures we reset the underlying SelectedSelectionKeySet data structures before we select - The loop bounds in NioEventLoop#processSelectedKeysOptimized can be defined more precisely because we know the real size of the underlying array Result: Fixes netty#6058
Motivation: SelectedSelectionKeySet currently uses 2 arrays internally and users are expected to call flip() to access the underlying array and switch the active array. However we do not concurrently use 2 arrays at the same time and we can get away with using a single array if we are careful about when we reset the elements of the array. Modifications: - Introduce SelectedSelectionKeySetSelector which wraps a Selector and ensures we reset the underlying SelectedSelectionKeySet data structures before we select - The loop bounds in NioEventLoop#processSelectedKeysOptimized can be defined more precisely because we know the real size of the underlying array Result: Fixes netty#6058
Uh oh!
There was an error while loading. Please reload this page.
Hi,
I was reading netty source code these days, netty is really a great project and the source code is so beautiful!
Now I have two questions to ask for your help:
purpose of ioRatio in NioEventLoop.
Does ioRatio mean the elapsed time of io operation?As the method
processSelectedKey
above is cpu intennsive(copy bytes from tcp buffer to jvm direct buffer), isioRatio
simply used to control the proportion of copy bytes and business task?Is there any other purpose,like efficiency? ^^perhaps two backed array in SelectedSelectionKeySet may be reduced to one.
I see this set is backed by two arrays, but I think use one array can also do the same thing as every time after
NioEventLoop
callprocessSelectedKeysOptimized(SelectionKey[] selectedKeys)
, the twoSelectionKey[]
is filled withNull
pointperhaps if the flip method is replaced with
end
method as follows can do the same and also avoid execif (isA)
^^Thank you for your help!!!
The text was updated successfully, but these errors were encountered: