Skip to content

Non-gunicorn multiprocessing (mostly questions) #130

Closed

Description

@tlc

I am trying to use multiprocessing support even though I am not using gunicorn.

I have a master proc calling multiprocessing.Process() to create workers. (I'm forking but not execing.)

All my mmap files in prometheus_multiproc_dir have the parent process id in the filename. I believe this is not as intended and means that stats are being aggregated as they're saved instead of when they're served. (A performance hit.)

I will try to import prometheus_client after the fork -- and in another file. But that file will be imported... Do the python imports make it impossible for me to have different global _ValueClass's without an exec or monkeying in prometheus_client?

Also, BTW, there is still a reference to shelve in the source.

Activity

  1. brian-brazil commented on Jan 24, 2017

    @brian-brazil
    Contributor

    We don't currently support multiprocessing, as it doesn't work the way we expect gunicorn-like things to.

  2. dozer47528 commented on Mar 7, 2017

    @dozer47528

    @brian-brazil I have the same problem, any plan to support uwsgi?

  3. brian-brazil commented on Mar 7, 2017

    @brian-brazil
    Contributor

    Can uwsgi start a brand new process for requests?

    We currently support a partiuclar model of using multiple processes, not particular libraries.

  4. dozer47528 commented on Mar 7, 2017

    @dozer47528

    I use uwsgi to start my application

    uwsgi --http-socket :8000 --master --workers 4 --enable-threads --threads 10 --wsgi-file server/wsgi.py

    There is one master process and four worker process.

    But the client_python only created one file with the pid of master process.

  5. brian-brazil commented on Mar 7, 2017

    @brian-brazil
    Contributor

    Unless you can find a way to make it fork&exec each worker, it's not going to work currently.

  6. banteg commented on Mar 18, 2017

    @banteg

    Working uWSGI config example:

    [uwsgi]
    env = prometheus_multiproc_dir=multi
    enable-threads = yes
    lazy-apps = yes
    
    http-socket = :8000
    processes = 4
    wsgi = app:app
  7. esseti commented on Apr 7, 2017

    @esseti

    @banteg can you provide a full example. this is the uwsgi ini file, but how/where do you start the wsgi_server? what port?

  8. ecksun commented on May 18, 2017

    @ecksun

    We don't currently support multiprocessing, as it doesn't work the way we expect gunicorn-like things to.

    We currently support a partiuclar model of using multiple processes, not particular libraries.

    There is not much documentation about what is and is not supported, nor what model you are refering to, could you expand on that @brian-brazil ?

    I have a kafka multiprocess worker which I want to export metrics from. The code below appears to work (I intend to use systemd ExecStopPost to cleanup afterwards), is there something I'm missing?

    def start_prometheus_server():
        class MetricsHandler(BaseHTTPRequestHandler):
            def do_GET(self):
                if self.path == '/metrics':
                    self.respond_metrics()
                else:
                    self.respond_not_found()
    
            def respond_not_found(self):
                self.send_response(404)
                self.send_header('Content-Type', 'text/plain')
                self.end_headers()
                self.wfile.write(b'Use /metrics\n')
    
            def respond_metrics(self):
                registry = CollectorRegistry()
                multiprocess.MultiProcessCollector(registry)
                data = generate_latest(registry)
                self.send_response_only(200)
                self.send_header('Content-Type', CONTENT_TYPE_LATEST)
                self.send_header('Content-Length', str(len(data)))
                self.end_headers()
                self.wfile.write(data)
    
        class PrometheusMetricsServer(threading.Thread):
            def run(self):
                httpd = HTTPServer(('', 8002), MetricsHandler)
                httpd.serve_forever()
    
        t = PrometheusMetricsServer()
        t.daemon = True
        t.start()
  9. brian-brazil commented on May 18, 2017

    @brian-brazil
    Contributor

    That's just the exposition part which will work anywhere (doesn't even have to be in a related process). The problem is the instrumentation part.

  10. ecksun commented on May 18, 2017

    @ecksun

    That's just the exposition part which will work anywhere (doesn't even have to be in a related process). The problem is the instrumentation part.

    Okay, what does that mean for me, will all my counters be wrong? Is it possible to get it to work currently at all?

  11. brian-brazil commented on May 18, 2017

    @brian-brazil
    Contributor

    If you're using multiprocessing it won't work currently.

  12. ecksun commented on May 18, 2017

    @ecksun

    If you're using multiprocessing it won't work currently.

    Alright, thats very sad to hear :(

    In which manners will it not work and why not? What changes are required to fix that?

  13. brian-brazil commented on May 18, 2017

    @brian-brazil
    Contributor

    See #127

  14. ecksun commented on May 18, 2017

    @ecksun

    Is it correct to assume that it would work to simply create multiple python processes (in my case I would use systemd templates) that share the same metrics dir?

    Also, sorry for continuing discussion on this closed issue, I feel there is a lack of documentation around what you can and can't do with regards to multiple processes with the python client, and more info in this issue would have helped me.

  15. brian-brazil commented on May 18, 2017

    @brian-brazil
    Contributor

    This is already being discussed on the other issue, so I consolidated.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions