Skip to content

Introduce ginterpreter worker#3491

Open
aisk wants to merge 14 commits intobenoitc:masterfrom
aisk:interpreter-worker
Open

Introduce ginterpreter worker#3491
aisk wants to merge 14 commits intobenoitc:masterfrom
aisk:interpreter-worker

Conversation

@aisk
Copy link
Copy Markdown

@aisk aisk commented Feb 6, 2026

Introduce a multi-interpreter–based worker that can handle multiple requests within the same process, each running in a separate interpreter, without sharing a GIL. This allows different interpreters to run in true parallelism.

This does not require a no-GIL build of Python, and it does not require users to handle thread-safe code at the Python level.

Features are missing:

  • SSL
  • Access log
  • Graceful shutdown
  • Keepalive
  • pre_request/post_request hooks
  • HTTP2
  • sendfile
  • Max requests
  • Comprehensive unit testing
  • Documentation

Comment thread gunicorn/workers/ginterpreter.py Outdated
@pajod
Copy link
Copy Markdown
Contributor

pajod commented Feb 6, 2026

Oh, this looked simple enough to give it a spin in a fair comparison against real workloads after "just" adding logging + keepalive.. but apparently I do not have 3.14 on Debian yet. Monitoring for later..

@aisk
Copy link
Copy Markdown
Author

aisk commented Feb 7, 2026

Oh, this looked simple enough to give it a spin in a fair comparison against real workloads after "just" adding logging + keepalive.. but apparently I do not have 3.14 on Debian yet. Monitoring for later..

Do you think it makes sense to add logging and keepalive support now?

@pajod
Copy link
Copy Markdown
Contributor

pajod commented Feb 7, 2026

Do you think it makes sense to add logging and keepalive support now?

Not yet, I guess. Hoping that most of missing bits and pieces (incl ssl) can be added with less worker-specific code later, as the rest of Gunicorn receives some much-needed refactoring.
Probably a good idea to edit the PR message to clarify current limitations of the patch, though.

Copy link
Copy Markdown
Owner

@benoitc benoitc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is interresting as it brings isolation. Do you want to complete it ?

Following changes are needed:

  1. Add access logging support (critical for production use)
  2. Add future tracking and connection counting (see review)
  3. Improve graceful shutdown handling (see review)
  4. Add integration tests
  5. Update documentation

Also please update the PR with the current limitatisn you may have found.

Comment thread gunicorn/workers/ginterpreter.py
Comment thread gunicorn/workers/ginterpreter.py Outdated
Comment thread gunicorn/workers/ginterpreter.py
@benoitc benoitc self-assigned this Feb 7, 2026
Comment thread gunicorn/workers/ginterpreter.py Outdated
@benoitc benoitc marked this pull request as draft March 13, 2026 09:21
@benoitc
Copy link
Copy Markdown
Owner

benoitc commented Mar 13, 2026

@aisk any news?

@aisk aisk marked this pull request as ready for review March 14, 2026 08:49
@aisk
Copy link
Copy Markdown
Author

aisk commented Mar 14, 2026

@benoitc Added basic document and features, I think this PR can be reviewed now.

@benoitc
Copy link
Copy Markdown
Owner

benoitc commented Mar 24, 2026

with subinterpreter why notconsidering instead of spawning new worker have one worker = 1 subinterpreter and insteadb ypassing gil. spawning subinterpreter can use ~ 50Mb of ram. thoughts?

@aisk
Copy link
Copy Markdown
Author

aisk commented Mar 25, 2026

with subinterpreter why notconsidering instead of spawning new worker have one worker = 1 subinterpreter and insteadb ypassing gil. spawning subinterpreter can use ~ 50Mb of ram. thoughts?

Current implementation is mainly based on the current gthread worker, so it may have multiple sub interpreters in multiple worker threads.

The only benefit with this design I can think of is that some code, especially some C extensions, may have resource leaks in the current process. Destroying the sub interpreter cannot eliminate this kind of leak. With this design, we can re-create the worker process to avoid the leak.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants