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

Improved pooling of buffers when a buffer was released in other thread. #73

Merged
merged 1 commit into from
Feb 21, 2016

Conversation

hide1202
Copy link
Contributor

resolve #63

Improved pooling of buffers when a buffer was released in other thread.

Motivation:

When buffer was released in other thread, this buffer couldn't be released. I think that need to release a buffer in other thread for memory effectiveness.

Modifications:

Implement WeakOrderQueue for releasing a buffer that other thread owned.

Result:

When buffer was released in othread thread, owned thread can use this buffer.

@azurecla
Copy link

Hi @hide1202, I'm your friendly neighborhood Azure Pull Request Bot (You can call me AZPRBOT). Thanks for your contribution!
You've already signed the contribution license agreement. Thanks!
We will now validate the agreement and then real humans will evaluate your PR.

TTYL, AZPRBOT;

@@ -41,21 +50,307 @@ public bool Release<T>(T value)
}
}

internal sealed class Stack : Stack<Handle>
internal sealed class WeakOrderQueue
Copy link
Member

Choose a reason for hiding this comment

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

why not private?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nayato If WeakOrderQueue were private, Stack couldn't access WeakOrderQueue. So WeakOrderQueue class has internal modifier.

Copy link
Member

Choose a reason for hiding this comment

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

I see, differences in Java vs .NET scope mechanics, ok.

@hide1202 hide1202 force-pushed the feature/improve-pool branch from fae24db to 2613b0d Compare February 20, 2016 10:54
class Link
{
internal int readIndex;
internal volatile int writeIndex;
Copy link
Member

Choose a reason for hiding this comment

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

pls switch to Volatile.Read/Write methods. see http://blog.alexrp.com/2014/03/30/dot-net-atomics-and-memory-model-semantics/ for details

@nayato
Copy link
Member

nayato commented Feb 20, 2016

pls check the comments above. I'll do another pass tomorrow with a fresh head. Thanks for taking on this. That's actually a great addition to an honest port of pooled byte buffer allocator I'm working on.

@hide1202
Copy link
Contributor Author

@nayato OK, I will check your comments. And i check more detailedly and i will fix it. And i will add commit in order that you check corrections easily. If you would check, i will rebase it. 😄
And RecycleID was excluded in this time. Note please.

@hide1202 hide1202 force-pushed the feature/improve-pool branch 2 times, most recently from d6fbcbd to 7fd8994 Compare February 21, 2016 08:15
@nayato
Copy link
Member

nayato commented Feb 21, 2016

@hide1202
Copy link
Contributor Author

@nayato OK, i will check your comments.

@nayato
Copy link
Member

nayato commented Feb 21, 2016

btw, with this change the reason for renaming Recycler into ThreadLocalPool is not there anymore so it would make sense to rename it back into Recycler. Not necessarily in this PR if it's a big change.

writeIndex = Volatile.Read(ref tail.writeIndex);
}
tail.elements[writeIndex] = handle;
//handle.Stack = null;
Copy link
Member

Choose a reason for hiding this comment

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

why is it commented out? If it's because Handle.Stack is readonly - remove the readonly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nayato OK!

@hide1202
Copy link
Contributor Author

@nayato I move ThreadLocalPoolTest to DotNetty.Common.Tests. (for accessing internal method)

@hide1202 hide1202 force-pushed the feature/improve-pool branch 2 times, most recently from 7dfa906 to 7541be9 Compare February 21, 2016 12:38
where T : class
{
Contract.Requires(value == this.Value, "value differs from one backed by this handle.");

Stack stack = this.Stack;
if (stack.Thread != Thread.CurrentThread)
if (stack.Thread == Thread.CurrentThread)
Copy link
Member

Choose a reason for hiding this comment

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

used twice => cache in local variable

internal Handle[] elements;

private int maxCapacity;
internal int head;
Copy link
Member

Choose a reason for hiding this comment

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

why not size?

@nayato
Copy link
Member

nayato commented Feb 21, 2016

@hide1202 now I think I'm done reviewing and it's OK to rebase/squash once this last batch of comments is out of the way.

@hide1202 hide1202 force-pushed the feature/improve-pool branch from 7541be9 to d43e6cf Compare February 21, 2016 22:49
Motivation:

When buffer was released in other thread, this buffer couldn't be released. I think that need to release a buffer in other thread for memory effectiveness.

Modifications:

Implement WeakOrderQueue for releasing a buffer that other thread owned.

Result:

When buffer was released in othread thread, owned thread can use this buffer.
@hide1202 hide1202 force-pushed the feature/improve-pool branch from d43e6cf to 5b1139e Compare February 21, 2016 22:51
@hide1202
Copy link
Contributor Author

@nayato I checked your comments, and fixed all. And rebase to one commit. 😃

nayato added a commit that referenced this pull request Feb 21, 2016
Improved pooling of buffers when a buffer was released in other thread.
@nayato nayato merged commit ae0798e into Azure:dev Feb 21, 2016
@nayato
Copy link
Member

nayato commented Feb 21, 2016

@hide1202 thanks for taking on this!

@hide1202 hide1202 deleted the feature/improve-pool branch February 21, 2016 23:22
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.

Improve release in ThreadLocalPool.Handle
3 participants