Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Use ForkJoinPool and provide builder API to limit threads count.#1092

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
mstyura wants to merge1 commit intoobjectbox:main
base:main
Choose a base branch
Loading
frommstyura:thread-pool-limits

Conversation

mstyura
Copy link

This PR provide API to configure thread pool limits use byBoxStore.

I was observed situation inAndroid application where (due to some other issues in app) application is crashed withOOM. At the moment of crash there were tens of alive threads belong toObjectBox pool. The numbering suggest that thousands of thread were already created and destroyed by the pool at the moment of crash.
So it would be nice to have an API to limit number of threads allowed in thread pool and minimum number of threads as well.
This of course will not solve original problem with app I was debugging, but will probably help to reveal root problem earlier.

Hartigan, greenrobot-team, and friendoye reacted with thumbs up emoji
@greenrobot-team
Copy link
Member

greenrobot-team commentedAug 16, 2022
edited
Loading

Thanks! Maybe we should also consider setting the maximum size to 64 (but at least number of processors) by default. (It's the default parallelism number for Kotlin's IO scheduler.)

@greenrobot-teamgreenrobot-team self-assigned thisAug 16, 2022
@mstyuramstyura changed the titleBuilder API to configure thread pool size.WIP: Builder API to configure thread pool size.Aug 16, 2022
@mstyuramstyura marked this pull request as draftAugust 16, 2022 20:44
@mstyura
Copy link
Author

Hi! I like the idea of having sane default limit to number of threads in pool.
I've tried to implement it. I've set default value to small value like4 and launched unit-tests.
I've started gettingRejectedExecutionException, which is not I wanted.
RejectedExecutionException had happen due to usage ofSynchronousQueue.
I've tried to use unboundedLinkedBlockingQueue, but with unbounded queue the onlycorePoolSize make sense.
Basically the meaning ofThreadPoolExecutor withcorePoolSize=X and unboundedLinkedBlockingQueue is an executor service which at maximum can runX tasks in parallel.
This is whatForkJoinPool does naturally, so I've decided to rather switch to it and only provide configuration to override maximum degree of parallelism.
There is one drawback is thatForkJoinPool allow changing keep alive thread timeout only on the very recent API level. I think this is acceptable for now to use default, while having sane limit to number of threads.

@mstyuramstyura marked this pull request as ready for reviewAugust 16, 2022 22:23
@mstyuramstyura changed the titleWIP: Builder API to configure thread pool size.Builder API to configure thread pool size.Aug 16, 2022
@mstyuramstyura changed the titleBuilder API to configure thread pool size.Use ForkJoinPool and provide builder API to limit threads count.Aug 16, 2022
@greenrobot-team
Copy link
Member

@mstyura Oh sorry, I didn't mean for you to implement this. With "we" I meant the ObjectBox team. But thanks for the investigation!

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees

@greenrobot-teamgreenrobot-team

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@mstyura@greenrobot-team

[8]ページ先頭

©2009-2025 Movatter.jp