-
Notifications
You must be signed in to change notification settings - Fork 6
MOD-13142 Option to resize mr thpool after creation, but not after started #89
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1564,6 +1564,24 @@ int MR_Init(RedisModuleCtx* ctx, size_t numThreads, char *password) { | |
| return REDISMODULE_OK; | ||
| } | ||
|
|
||
| int MR_ResizeExecutionThreadPoolIfUnstarted(size_t numThreads) { | ||
| mr_threadpool tp = mrCtx.executionsThreadPool; | ||
|
|
||
| /* MR_Init() not called yet. */ | ||
| if (!tp) { | ||
| return REDISMODULE_OK; | ||
| } | ||
|
|
||
| if (mr_thpool_workers_started(tp)) { | ||
| return REDISMODULE_ERR; | ||
| } | ||
|
|
||
| if (mr_thpool_resize_unstarted(tp, numThreads) != 0) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Implicit
|
||
| return REDISMODULE_ERR; | ||
| } | ||
| return REDISMODULE_OK; | ||
| } | ||
|
|
||
| int MR_RegisterObject(MRObjectType* t) { | ||
| mrCtx.objectTypesDict = array_append(mrCtx.objectTypesDict, t); | ||
| t->id = array_len(mrCtx.objectTypesDict) - 1; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -141,8 +141,9 @@ struct mr_thpool_* mr_thpool_init(int num_threads) { | |
| threads_on_hold = 0; | ||
| threads_keepalive = 1; | ||
|
|
||
| if (num_threads < 0) { | ||
| num_threads = 0; | ||
| if (num_threads <= 0) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the old code allowed 0? Was it "unlimited" maybe?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dont think so. When it was 0, its just kept allocating 0 bytes for the threads, which is 0 threads(and is there a reason we should allow it)? |
||
| err("thpool_init(): num_threads must be greater than 0\n"); | ||
| return NULL; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
| /* Make new thread pool */ | ||
|
|
@@ -180,6 +181,42 @@ struct mr_thpool_* mr_thpool_init(int num_threads) { | |
| return thpool_p; | ||
| } | ||
|
|
||
| int mr_thpool_workers_started(mr_threadpool thpool) { | ||
| return thpool != NULL && thpool->is_threads_started; | ||
|
AvivDavid23 marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| int mr_thpool_resize_unstarted(mr_threadpool thpool, int num_threads) { | ||
|
|
||
| if (thpool == NULL) { | ||
| return -1; | ||
| } | ||
|
|
||
| if (num_threads <= 0) { | ||
| err("mr_thpool_resize_unstarted(): num_threads must be greater than 0\n"); | ||
| return -1; | ||
| } | ||
|
|
||
| pthread_mutex_lock(&thpool->is_threads_started_lock); | ||
| if (thpool->is_threads_started) { | ||
| pthread_mutex_unlock(&thpool->is_threads_started_lock); | ||
| err("mr_thpool_resize_unstarted(): workers already started\n"); | ||
| return -1; | ||
| } | ||
|
|
||
| mr_thread** new_pool = | ||
| (mr_thread**)MR_REALLOC(thpool->threads, (size_t)num_threads * sizeof(struct mr_thread*)); | ||
| if (new_pool == NULL) { | ||
| pthread_mutex_unlock(&thpool->is_threads_started_lock); | ||
| err("mr_thpool_resize_unstarted(): realloc failed\n"); | ||
| return -1; | ||
| } | ||
|
|
||
| thpool->threads = new_pool; | ||
| thpool->total_num_of_threads = num_threads; | ||
| pthread_mutex_unlock(&thpool->is_threads_started_lock); | ||
| return 0; | ||
| } | ||
|
AvivDavid23 marked this conversation as resolved.
|
||
|
|
||
| /* Add work to the thread pool */ | ||
| int mr_thpool_add_work(mr_thpool_* thpool_p, void (*function_p)(void*), void* arg_p) { | ||
| mr_job* newjob; | ||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.