Skip to content

Add resizable write/search queue to OpenSearch#826

Closed
rguo-aws wants to merge 2 commits intoopensearch-project:mainfrom
rguo-aws:resizable-q-2
Closed

Add resizable write/search queue to OpenSearch#826
rguo-aws wants to merge 2 commits intoopensearch-project:mainfrom
rguo-aws:resizable-q-2

Conversation

@rguo-aws
Copy link
Copy Markdown
Contributor

@rguo-aws rguo-aws commented Jun 8, 2021

Signed-off-by: Ruizhen ruizhen@amazon.com

Description

Create a new type of threadpool queue "OpenSearchResizableBlockingQueue" to dynamically adjust search queue size in runtime.
The current threadpool queue for search is of "FIXED" type and the queue capacity can only be updated via opensearch.yml.

This OpenSearchResizableBlockingQueue that is introduced in this PR can allow us to make changes to queue size without restarting OpsearchSearch process.

Also addressed unit test failures in this PR

Issues Resolved

#476

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: Ruizhen <ruizhen@amazon.com>
@opensearch-ci-bot
Copy link
Copy Markdown
Collaborator

✅   DCO Check Passed 507b3c7

@opensearch-ci-bot
Copy link
Copy Markdown
Collaborator

✅   Gradle Wrapper Validation success 507b3c7

@opensearch-ci-bot
Copy link
Copy Markdown
Collaborator

✅   Gradle Precommit success 507b3c7

@harold-wang
Copy link
Copy Markdown
Contributor

start gradle check

@opensearch-ci-bot
Copy link
Copy Markdown
Collaborator

❌   Gradle Check failure 507b3c7
Log 227

Reports 227

@AmiStrn
Copy link
Copy Markdown
Contributor

AmiStrn commented Jun 14, 2021

I think the commit message should have a bit more content describing what was done, I have seen quite a few commits to main recently that have either a messy changelog or no message at all.
I will open an issue regarding this in the forums and link here, but this is a current PR that maybe can be fixed:)
A good reference is https://dhwthompson.com/2019/my-favourite-git-commit

// 5.x doesn't know about the "fixed_auto_queue_size" thread pool type, just write fixed.
out.writeString(ThreadPoolType.FIXED.getType());
} else if (type == ThreadPoolType.RESIZABLE) {
// old vfi doesn't know about "resizable" thread pool. Convert RESIZABLE to FIXED
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.

Can you please use the full term instead of the acronym vfi? acronyms are sometimes a burden for developers to feel comfortable with the project, especially when they are in a comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing this out, I rephrased my comments and removed "vfi" from it

//TODO: The executor of our new SiFi resizable search queue is OpenSearchThreadPoolExecutor which
// unfortunately does not keep track of queueSize/EWMA execution time. We should ideally Add EWMA enabled threadpool
// executor and reenable the below unit test
// EWMATrackingEsThreadPoolExecutor from ES 8.0 and re-enable the below unit test.
Copy link
Copy Markdown
Contributor

@AmiStrn AmiStrn Jun 14, 2021

Choose a reason for hiding this comment

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

I don't think anything should be taken from ES 8.0 as it is not Apache License Version 2.0.
I would definitely rephrase this comment and refrain from writing things that would lead anyone to believe (wrongfully) that the code is "from" anywhere but your own original design 😬

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry for the confusion. We do not have intent to port code from ES 8.0. It was an error in comments and I've already cleared it up

public static OpenSearchThreadPoolExecutor newResizable(String name, int size, int queueCapacity,
ThreadFactory threadFactory, ThreadContext contextHolder) {
BlockingQueue<Runnable> queue;
if (queueCapacity < 0) {
Copy link
Copy Markdown
Contributor

@AmiStrn AmiStrn Jun 14, 2021

Choose a reason for hiding this comment

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

does it make any sense to be ok with a queue size of 0?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, Queue size can be set to -1 to make it unbounded. This is to handle the case where queue size is -1 in opensearch.yml

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.

I am asking specifically about 0 though. I get the need for a -1 (although a bit confusing) as a flag for unbounded. I am asking to understand more than any form of critique of course:)

if (queueCapacity < 0) {
queue = ConcurrentCollections.newBlockingQueue();
} else {
queue = new SifiResizableBlockingQueue<>(ConcurrentCollections.<Runnable>newBlockingQueue(),
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.

Suggested change
queue = new SifiResizableBlockingQueue<>(ConcurrentCollections.<Runnable>newBlockingQueue(),
queue = new OpenSearchResizableBlockingQueue<>(ConcurrentCollections.<Runnable>newBlockingQueue(),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thanks. made the changed as per your suggestion

map.put(Names.ANALYZE, ThreadPoolType.FIXED);
map.put(Names.WRITE, ThreadPoolType.FIXED);
map.put(Names.SEARCH, ThreadPoolType.FIXED_AUTO_QUEUE_SIZE);
map.put(Names.WRITE, ThreadPoolType.RESIZABLE);
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.

Do we really need to change WRITE threadpool as they have been moved to support byte-size based defaulting to 10k

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

that is a very good point. yes, there is actually no need to change write to resizable anymore

Comment on lines +1870 to +1879
// Note: Disable this, since search pool has been changed to be of type RESIZABLE, which does not support a
// min_queue_size setting.
/*
if (rarely()) {
// Sometimes adjust the minimum search thread pool size, causing
// QueueResizingOpenSearchThreadPoolExecutor to be used instead of a regular
// fixed thread pool
builder.put("thread_pool.search.min_queue_size", 100);
}
*/
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.

Remove rather than comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

* Mainly makes sense to use with blocking queues that are unbounded to provide the ability to do
* capacity verification.
*/
public class SifiResizableBlockingQueue<E> extends SizeBlockingQueue<E> {
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.

Rename better

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

@nknize nknize added enhancement Enhancement or improvement to existing feature or request v1.1.0 Issues, PRs, related to the 1.1.0 release v2.0.0 Version 2.0.0 labels Jun 25, 2021
Signed-off-by: Ruizhen <ruizhen@amazon.com>
@opensearch-ci-bot
Copy link
Copy Markdown
Collaborator

✅   DCO Check Passed 96352ea

@opensearch-ci-bot
Copy link
Copy Markdown
Collaborator

✅   Gradle Wrapper Validation success 96352ea

@opensearch-ci-bot
Copy link
Copy Markdown
Collaborator

✅   Gradle Precommit success 96352ea

@opensearch-ci-bot
Copy link
Copy Markdown
Collaborator

✅   DCO Check Passed 96352ea

@opensearch-ci-bot
Copy link
Copy Markdown
Collaborator

✅   Gradle Wrapper Validation success 96352ea

@opensearch-ci-bot
Copy link
Copy Markdown
Collaborator

✅   Gradle Precommit success 96352ea

* Mainly makes sense to use with blocking queues that are unbounded to provide the ability to do
* capacity verification.
*/
public class OpenSearchResizableBlockingQueue<E> extends SizeBlockingQueue<E> {
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.

What are the reasons to introduce this class instead of using the existing ResizableBlockingQueue ?


private final BlockingQueue<E> queue;
private final int capacity;
protected volatile int capacity;
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.

I think this change should not be taken lightly: the truly fixed size queues (SizeBlockingQueue) would have to pay a price of accessing the volatile field which is only adjustable for resizeable queues.

@anasalkouz anasalkouz removed the v1.1.0 Issues, PRs, related to the 1.1.0 release label Sep 7, 2021
@opensearch-ci-bot
Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

@anasalkouz
Copy link
Copy Markdown
Member

@rguo-aws are you working on this? there are couple of comments need to be addressed.

@opensearch-ci-bot
Copy link
Copy Markdown
Collaborator

✅   Gradle Wrapper Validation success 96352ea

@opensearch-ci-bot
Copy link
Copy Markdown
Collaborator

✅   DCO Check Passed 96352ea

@opensearch-ci-bot
Copy link
Copy Markdown
Collaborator

✅   Gradle Precommit success 96352ea

@dblock
Copy link
Copy Markdown
Member

dblock commented Mar 3, 2022

@AmiStrn or @reta any interest in picking this up from where @rguo-aws left it at?
Otherwise @anasalkouz, let's find an owner to finish this?

@AmiStrn
Copy link
Copy Markdown
Contributor

AmiStrn commented Mar 3, 2022

Thanks @dblock but Im not available for this in this quarter, so I kindly decline.

@reta
Copy link
Copy Markdown
Contributor

reta commented Mar 3, 2022

@dblock I am in, will take a look shortly

@tlfeng tlfeng added v3.0.0 Issues and PRs related to version 3.0.0 and removed v2.0.0 Version 2.0.0 labels Apr 2, 2022
@tlfeng tlfeng removed the v3.0.0 Issues and PRs related to version 3.0.0 label Apr 11, 2022
@CEHENKLE
Copy link
Copy Markdown
Member

CEHENKLE commented May 4, 2022

Hey @reta ! Are you still thinking about this one? Thanks!

@reta
Copy link
Copy Markdown
Contributor

reta commented May 4, 2022

@CEHENKLE yes! I will pick up shortly, thanks for reminding !

@CEHENKLE
Copy link
Copy Markdown
Member

CEHENKLE commented May 4, 2022

@reta Cool beans -- thanks! :)

@reta
Copy link
Copy Markdown
Contributor

reta commented May 5, 2022

@CEHENKLE continuing the work in https://github.com/opensearch-project/OpenSearch/pull/3207/files since I cannot push changes to the original branch.

@reta
Copy link
Copy Markdown
Contributor

reta commented May 6, 2022

Closing in favor of #3207

@reta reta closed this May 6, 2022
dblock pushed a commit that referenced this pull request May 16, 2022
* Make search/write queue resizable

Signed-off-by: Ruizhen <ruizhen@amazon.com>

* Address PR comments

Signed-off-by: Ruizhen <ruizhen@amazon.com>

* Refactoring resizable queue implementation

Signed-off-by: Andriy Redko <andriy.redko@aiven.io>

* Addressing code review comments

Signed-off-by: Andriy Redko <andriy.redko@aiven.io>

* Addressing code review comments

Signed-off-by: Andriy Redko <andriy.redko@aiven.io>

* Addressing code review comments

Signed-off-by: Andriy Redko <andriy.redko@aiven.io>

Co-authored-by: Ruizhen <ruizhen@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Enhancement or improvement to existing feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.