Skip to content
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

Why rq is forking on every job? #210

Closed
observerss opened this issue Apr 26, 2013 · 2 comments
Closed

Why rq is forking on every job? #210

observerss opened this issue Apr 26, 2013 · 2 comments

Comments

@observerss
Copy link

The default fork-on-job behavior makes my connection pools (to database) useless, thus add unnecessary load on both "work horse" machine and database machine.

Since I know I don't need to sandbox the environment for each job, I did a trick like this

class NoforkWorker(Worker):
    def fork_and_perform_job(self, job):
        self.main_work_horse(job)
        self._horse_pid = os.getpid()

    def main_work_horse(self, job):
        self._is_horse = True
        success = self.perform_job(job)
        self._is_horse = False

# Provide queue names to listen to as arguments to this script,
# similar to rqworker
with Connection():
    w = NoforkWorker([job_queue])
    w.work()

This is so significant that it reduces the load average on work horse machine from 30+ to 1, database machine's cpu usage reduced from 10-20% -> 4%

Would I break something in this way?

@selwin
Copy link
Collaborator

selwin commented May 7, 2013

@nvie explained the reasoning behind the initial choice of using os.fork here.

We are in the process of reworking some of the internals to support different worker classes. However, it's a complicated job and progress on that has been kind of slow. You can see the full discussion on this issue

@selwin
Copy link
Collaborator

selwin commented Sep 14, 2013

Duplicate of #45

@selwin selwin closed this as completed Sep 14, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants