python-diamond / Diamond

Diamond is a python daemon that collects system metrics and publishes them to Graphite (and others). It is capable of collecting cpu, memory, network, i/o, load and disk metrics. Additionally, it features an API for implementing custom collectors for gathering metrics from almost any source.
http://diamond.readthedocs.org/
MIT License
1.74k stars 601 forks source link

Will this code in server.py mess the log? #691

Open kramerli opened 6 years ago

kramerli commented 6 years ago

I can see below code in server.py

    handlers_process = multiprocessing.Process(
        name="Handlers",
        target=handler_process,
        args=(self.handlers, self.metric_queue, self.log),
    )

I did some search on the internet, a lot posts said that logging do not have a lock between process. So use log in multiprocessing may cause the content of log be messed.

Will this code have this kind of problem? If not then why?

DStape commented 6 years ago

Hi @kramerli,

This is a good question. Writing to the same file from different processes can result in weird behaviour - the data written might be interleaved and/or incomplete, or worse, the file may become corrupted. I think there will be other factors in play though, for example what type of file system is in use.

I think this is something that will have to be investigated further and fixed.