emmett-framework / granian

A Rust HTTP server for Python applications
BSD 3-Clause "New" or "Revised" License
2.6k stars 77 forks source link

Maximum number of open files #385

Open mindflayer opened 3 weeks ago

mindflayer commented 3 weeks ago

It'd be great if we had a way to set the max number of file descriptors. See for instance the uWSGI setting for it: https://uwsgi-docs.readthedocs.io/en/latest/Options.html#max-fd

gi0baro commented 3 weeks ago

It'd be great if we had a way to set the max number of file descriptors.

I'm not sure complicating Granian code to manage system related stuff is a good idea. What prevents you from using the relevant system configuration utilities for this (like sysctl and ulimit, or some supervisors)?

mindflayer commented 3 weeks ago

Of course it's something I could fix in a different way. I've just changed the command with the prefix prlimit -n=8192 to set it at the process level.

It's worth mentioning I thought it was a simple change, and I believe it's a nice setting to have. Why did I think it was simple? Because in Python there is a simple way to play with resources: https://docs.python.org/3/library/resource.html.

The main reason for it would be not depending on external packages/commands. In the end ulimit values are usually specific to the application I am running, and I love to keep all the settings for an application in the same place.

mindflayer commented 3 weeks ago

This said, feel free to close the issue if it's outside the scope of granian, and kudos for what you achieved.

gi0baro commented 3 weeks ago

It's worth mentioning I thought it was a simple change, and I believe it's a nice setting to have. Why did I think it was simple? Because in Python there is a simple way to play with resources: https://docs.python.org/3/library/resource.html.

AFAIK, resource is available in Unix only, whereas Granian also supports Windows. Also I'm not sure about the implications of those limits with child processes, given that's the actual Granian implementation for workers.

That being said, I'm not completely against some limits features in Granian, as soon as the implementation is clearly documented (an option might be to describe those parameters are Unix-available only and warn the users in other cases). In the end: right now I don't have time to invest on this given the current priorities, but I'm willing to review PRs in this direction.