-
-
Notifications
You must be signed in to change notification settings - Fork 418
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
Codify the pony(min)threads behavior #3303
Conversation
src/libponyrt/sched/start.c
Outdated
@@ -93,6 +96,7 @@ static int parse_opts(int argc, char** argv, options_t* opt) | |||
{ | |||
case OPT_THREADS: opt->threads = atoi(s.arg_val); break; | |||
case OPT_MINTHREADS: opt->min_threads = atoi(s.arg_val); break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm not mistaken this silently overflows… (e.g. if -1
negative values are provided)
src/libponyrt/sched/start.c
Outdated
@@ -148,6 +152,17 @@ PONY_API int pony_init(int argc, char** argv) | |||
exit(0); | |||
} | |||
|
|||
if (opt.noscale) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the description on the issue, I think this shouldn't take precedence… yet dunno how I can make sure it actually was explicitly set (with 0
being the default currently). Also what should it do it opt.min_threads == opt.threads
, as that'd be the equivalent of opt.noscale
…
src/libponyrt/sched/start.c
Outdated
|
||
if (opt.min_threads > opt.threads) | ||
{ | ||
printf("Can't have --ponyminthreads > --ponythreads (%d > %d)\n", opt.min_threads, opt.threads); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like other errors aren't on stderr
, but should they be?
Also is -1
as a return fine?
Took a shot at prohibiting |
@@ -1076,7 +1076,7 @@ pony_ctx_t* ponyint_sched_init(uint32_t threads, bool noyield, bool nopin, | |||
|
|||
// If minimum thread count is > thread count, cap it at thread count | |||
if(min_threads > threads) | |||
min_threads = threads; | |||
min_threads = threads; // this becomes the equivalent of --ponynoscale |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we remove this entirely now then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As, with the current implementation, this would be triggered in such a case:
$ ./helloworld --ponyminthreads=2048
Hello, world.
Would it be better to bail out here instead? wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a proposal: an explicit check against physical cores:
$ ./helloworld --ponyminthreads=2048
Can't have --ponyminthreads > physical cores (2048 > 6)
I think this makes the most sense.
Magic value for what but being provided? By default minthreads default should be 0. I think your other questions are answered in the ticket. See #3152 (comment) |
Should have added a note, I think the latest stuff does that:
I just use a Open questions:
Someone may want to review my error messages too… Never feel I do a good job at these! |
Alright, I think that's fairly complete. Added the check for when not specifying
Let me know what you think! |
{ | ||
if (minthreads_set) | ||
{ | ||
printf("--ponyminthreads & --ponynoscale are mutually exclusive\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
src/libponyrt/sched/start.c
Outdated
@@ -150,6 +172,12 @@ PONY_API int pony_init(int argc, char** argv) | |||
|
|||
ponyint_cpu_init(); | |||
|
|||
if (opt.threads == 0 && opt.min_threads > ponyint_cpu_count()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be added the CHANGELOG.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add it!
Alex this looks pretty good. Small thing. You are checking to see if minthreads is greater than cores. We discussed and think that that should be if threads is greater than number of cores, it should be disallowed. Once that is in, do you feel comfortable updating the performance cheat sheet section related to this? https://www.ponylang.io/reference/pony-performance-cheatsheet/#ponythreads |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small thing. You are checking to see if minthreads is greater than cores. We discussed and think that that should be if threads is greater than number of cores, it should be disallowed.
So I'd this on top of the current code that checks for --ponyminthreads
being larger than the amount of cores, right? The reason I added this is when people specify min threads without specifying --ponythreads
. I guess it indeed also makes sense in the latter case tho. So again, currently the code does this:
$ ./helloworld --ponyminthreads=2048
Can't have --ponyminthreads > physical cores (2048 > 6)
I can add this behavior, which I think is indeed just as sensible:
$ ./helloworld --ponythreads=2048
Can't have --ponythreads > physical cores (2048 > 6)
Which I think is what you are asking for… I could also set opt.threads
to be the amount of cores in start.c
. I'm trying to avoid that this code silently "scales things" down… e.g. if the --ponyminthreads
> than the amount of cores and --ponythreads
defaulting to the amount of cores being unspecified with the arguments provided while starting up the process...
I'll add this to this PR in any case, but want to make sure we're all in agreement here.
Two questions remain unaddressed:
- Should we return
-1
, i.e255
as the process' return code on failures related to the runtime config? - Should we add checks for these args not being less than
0
rather than just assign the (signed)int
fromatoi
to anunsigned int
field?
Thanks for the review already!
src/libponyrt/sched/start.c
Outdated
@@ -150,6 +172,12 @@ PONY_API int pony_init(int argc, char** argv) | |||
|
|||
ponyint_cpu_init(); | |||
|
|||
if (opt.threads == 0 && opt.min_threads > ponyint_cpu_count()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add it!
I'm not sure of all the permutations of things to check for. Minthreads without setting threads is something I'd never do. But I guess you could do it (although in my mind it would be odd) so I can see how having that check makes sense.
Are you asking if there should be checks to make sure someone doesn't do --ponyminthreads=-1 ? |
I agree it's not really sensible to me neither, but would it in virtualized environments? Where I don't ever want less than 2 threads, but say for some reason I'm deploying on a single vCPU node? Dunno… nothing prohibits setting In anycase, I think 36d9123 does what you wanted (i.e. check for
Yeah, cause currently:
Which might be surprising to some (tho to others, the issue is probably very obvious!) |
btw, I realize the |
I'm not worried about the negative value issue, but checking it isn't less than 0 and reporting on that would be a nice UI improvement. I think that would make sense as a commit unto itself. |
I didn't follow that. Sorry, can you try saying in another way?
sounds wrong to me. if ponyminthreads is greater than ponythreads, that should error out. which is not what i think you are saying in the quoted bit. |
I can avoid the explicit check, and let the code in scheduler.c reduce minthreads to threads "silently" (the code I added was trying to avoid silently changing user settings), if you think that's preferable. But in that case I'd be explicit about it in the docs…
Right, but Cool, I'll prepare all of this in a cleaned up commit history and with all the changes discussed. (I'll start tonight, but … will probably push it all only tomorrow) |
Still not sure I follow. But, I'm in favor of explicit checks and explicit errors as a general rule of thumb.
Sorry @alexsnaps. I still didn't follow that. |
No worries, that last bit:
Is what I'm arguing for too! So I'll just:
And hopefully we can agree this all makes sense :) As I said on Zulip tho, and as you can now see here, I trust my code more than my English sentences, so please, please, double review the error messages! :) |
Sounds good @alexsnaps! |
Consolidated output & errors on my 6 core CPU:
Behavior is unchanged
This is fine, given
Explicit case, all good as
Explicit case, but with erronous values provided
Explicit case, but with
Incompatible arguments provided
Explicit case with erronous values and incompatible args. The latter error wins…
I'll still:
|
@alexsnaps let me know when you are ready for another review (and maybe even... a merge!) |
Wrapping up the doc & unsigned atoi at the airport (and on the flight if need be) right now… I think this should be fine in the next couple of hours… |
I’m again a disappointment. Didn’t get to finish the So if you think that behavior sounds good, let’s say this is ready for actual review and possibly a merge. I’ll open the PR against the other repo tomorrow (as I forgot to clone it prior boarding). wdyt? And sorry about the slow follow up here. |
@alexsnaps couple of things before full review. 1- are you comfortable rebasing against master to resolve the CHANGELOG.md conflict? |
@alexsnaps fyi, im planning on reviewing this today or tomorrow. i'd like for it to go out with the 0.32.0 release. |
Like so: $ ./helloworld --ponythreads=2048 Can't have --ponythreads > physical cores (2048 > 6)
@@ -107,6 +112,16 @@ static int parse_opts(int argc, char** argv, options_t* opt) | |||
} | |||
} | |||
|
|||
if (opt->noscale) | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small nit. this can be fixed in another PR. this {
should be on the preceding line.
if (opt->noscale) | ||
{ | ||
if (minthreads_set) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small nit. this can be fixed in another PR. this {
should be on the preceding line.
opt.threads = ponyint_cpu_count(); | ||
} | ||
else if (opt.threads > ponyint_cpu_count()) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small nit. this can be fixed in another PR. this {
should be on the preceding line.
} | ||
|
||
if (opt.min_threads > opt.threads) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small nit. this can be fixed in another PR. this {
should be on the preceding line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was the style most present in the code base. Not my preference neither… but I try to keep things consistent in a code base, if only one file. If we want {
on the same line (my preference 😃 and which is what I understand you are asking for) should I do a single commit formatting pass throughout the file?
@alexsnaps this looks good. there's a few small |
Draft in order to fix #3152
This won't work… I have many questions already but, wrt the issue at hand:
-1
, tho it's currently auint32_t
;--ponynoscale
when--ponyminthreads
wasn't provided?--ponyminthreads
==--ponythreads
and yet--ponynoscale
is provided; these two would effectively mean the same thing…Trying to get the discussion going… I'll then wrap this up (and update the usage and other docs if these exists)