-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add new CLI options #2237
Add new CLI options #2237
Conversation
"Run with maximum allowable processes.\nThis should be equal " | ||
"to the number of CPU processes available.\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.
This message is hard to understand. Maybe something along the lines of use all available CPUs
?
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.
It is worth a note that this does not (until 22.3) disable access logs, or change logging level (not sure if the latter would affect benchmarks). I suppose this is fine if at 22.3 the default mode is steered towards or even merged with the production mode.
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 threw together a quick little test to check the performance of a simple loop with different logging.
import logging
import timy
LOOPS = 10_000
RANGE = 1_000
LOG = logging.getLogger(__name__)
@timy.timer(loops=LOOPS)
def normal():
LOG.setLevel(logging.WARNING)
c = 0
for i in range(RANGE):
c += 1
@timy.timer(loops=LOOPS)
def with_logging_warning():
LOG.setLevel(logging.WARNING)
c = 0
for i in range(RANGE):
c += 1
LOG.debug("something")
@timy.timer(loops=LOOPS)
def with_logging_debug():
LOG.setLevel(logging.DEBUG)
c = 0
for i in range(RANGE):
c += 1
LOG.debug("something")
normal()
with_logging_warning()
with_logging_debug()
The results on my machine:
Timy executed (normal) for 10000 times in 0.338087 seconds
Timy best time was 0.000031 seconds
Timy executed (with_logging_warning) for 10000 times in 2.469493 seconds
Timy best time was 0.000234 seconds
Timy executed (with_logging_debug) for 10000 times in 77.279574 seconds
Timy best time was 0.007269 seconds
Conclusion: changing the logging level has a huge impact on performance. But, even the existence of the not impacted log call is not trivial either. If we are steering towards trying to impress benchmarks, then limiting or removing unused log
calls completely should make a difference.
An afterthought, perhaps we should utimately have The drawback is that the default mode would then have to be a genuine production mode, probably no motd or anything extra on the logs, which then could be confusing for some newcomers. If this is to be implemented, it would indeed be best to change the default mode to what this PR proposed as As discussed before, |
Most daemons print a single-line "motd" on logs when starting, which is actually informative, perhaps that could be kept in all modes to avoid some of the confusion? Print the address and port being listened to and that it is in production mode using N CPUs (processes), but not the full ASCII art logo? |
Related but not to this PR: it would be cool if someone redid the logo in xterm256-color or ANSI color and Unicode graphemes. A lot of Unix software is now taking advantage of these, and most terminals seem to support the extended colors and a fairly large selection of Unicode graphemes, even colored emoji and all that now. Although granted, they might display wrong on Which brings us to one option, only print the motd when a (suitable) TTY is detected, not if the output is redirected (to syslog). Then it would not need to depend on CLI options at all. if sys.stdout.isatty():
# You're running in a real terminal
else:
# You're being piped or redirected |
Also one point, since all CPUs nowadays have hyperthreading, my benchmarks show nearly identical performance no matter if you use the number of physical or logical CPUs, although the double number of workers (i.e. logical CPU count) seems to be a tad faster. This gives some headroom for some workers being stuck on I/O and not consuming a CPU, and I think both Intel and AMD can take advantage of instruction reordering via HT to better avoid pipeline stalls, giving a modest increase in total throughput if but HT cores of a physical CPU are fully loaded (contrary to HT when it was first introduced many years ago, when it would actually slow throughput a a bit when fully loaded, although it still improved scheduling latency, which was particularly helpful for interactive use on Windows which at the time had a very bad kernel scheduler that would otherwise cause noticeable stalls on desktop use). |
Yet another concern, I would prefer to keep |
I am not opposed to this, with the caveat that we slowly introduce the change so no breaks between now and the end of the year.
🤔 MOTD may be okay still. I am thinking specifically of celery which still has a startup message even when you are running in prod. I suppose maybe we can add an arg or config to suppress it if someone really does not want to add it. I honestly am moving more towards the opinion that we should make it more clear what is being run at startup, which can then provide people with an easy copy/paste for support.
Okay... so I think we are in agreement here. This is what I was thinking.
This is a nice point. I have gone back and forth in my head a lot for a while about whether it would or would not be a good idea to add ANSI colors to logging. This might be a good way to do it. Regarding the logo in particular, in what modes do you think it is appropriate to display it? If it is not so big and in the way, maybe we add it to MOTD if in TTY. No logo if logs are being redirected, and if we have a
I agree in principle. But, if you are doing |
Could use As it turned out, implementing good logic for finding the CPU count is non-trivial, thus it is better if app developers can use the existing logic even with |
Okay, so I have gone back to the drawing board a little on this:
|
Revised proposal:
When
|
Maybe change And in contrast to the current code on this PR, I guess the plan was to remove the |
I like that. The alternative could be a verbosity level on debug mode.
Yes. I have an implementation locally but it still has a lot of junk in it that I need to cleanup before pushing here. TBH, I might scrap this PR altogether and just create a new one. |
Moved to #2295 |
Implements and closes #2169
As mentioned here, this adds some new flags the the CLI:
--mode
Can be eitherdebug
orprod
WARNING
--dev
is a shortcut to DEBUG mode + auto-reload--fast
is a shortcut to max out the available workers