{"id":1376,"date":"2010-08-25T04:05:38","date_gmt":"2010-08-24T18:05:38","guid":{"rendered":"http:\/\/www.somethinkodd.com\/oddthinking\/?p=1376"},"modified":"2010-08-25T04:05:38","modified_gmt":"2010-08-24T18:05:38","slug":"introducing-nonblocking-log-handler","status":"publish","type":"post","link":"https:\/\/www.somethinkodd.com\/oddthinking\/2010\/08\/25\/introducing-nonblocking-log-handler\/","title":{"rendered":"Introducing Nonblocking Log Handler"},"content":{"rendered":"<p>(Just tidying up some loose ends.)<\/p>\n<p>I once <a href=\"http:\/\/www.somethinkodd.com\/oddthinking\/2010\/04\/29\/how-python-logging-bit-me-part-1\/\">complained about Python Logging<\/a> and its performance for real-time systems. <\/p>\n<p>It was suggested in the comments by the owner of the Python Logging module that I make a custom version for my needs. I protested that I didn&#8217;t think I was that special, and it should be available to everyone.<\/p>\n<p>Nothing happened for a few weeks, until <a href=\"http:\/\/www.somethinkodd.com\/oddthinking\/2010\/05\/25\/python-message-buffering-logging-handler-design-notes\/\">I got bitten by my inaction<\/a> and I decided I should try to make a solution for everyone. In that same post, I laid out the design for a solution that should work for everyone.<\/p>\n<p>The next day, I pointed out <a href=\"http:\/\/www.somethinkodd.com\/oddthinking\/2010\/05\/26\/python-consumer-thread-shutdown-design-notes\/\">a difficult problem with Python shutdown<\/a> which sounded like it should be a lot easier than it was.<\/p>\n<p>One of the OddThinking regulars, configurator, <a href=\"http:\/\/www.somethinkodd.com\/oddthinking\/2010\/05\/26\/python-consumer-thread-shutdown-design-notes\/#comment-229184\">pointed out<\/a> that I was being too thread-averse. Being willing to create threads more frequently gave me a simple solution. Performance tests showed I need not be that worried about the cost of threads in the typical case. Thanks, configurator. I proceeded with the implementation.<\/p>\n<p>I have shared that solution with others, and it has earned a few raised eyebrows. However, configurator&#8217;s suggestion seems to be the only one that gives correct behaviour, which counts for an awful lot. It also, in the typical case, is quite performant.<\/p>\n<p>The concern is that it may perform badly in the case of a run-away thread emitting log messages in an infinite loop. Without the plain logging solution, this would be I\/O bound, sending emails as quickly as it could, while the rest of the system kept performing normally. Under my implementation, I would expect the number of threads to explode. I assume this would have a heavy toll on other threads and processes in the operating system.<\/p>\n<p>So I am still open to less thread-intensive implementations, I just don&#8217;t know what they are. Please revisit <a href=\"http:\/\/www.somethinkodd.com\/oddthinking\/2010\/05\/26\/python-consumer-thread-shutdown-design-notes\/\">the discussion<\/a> if you have any ideas.<\/p>\n<p>Anyway, I completed the implementation called the Nonblocking Log Handler, made it available in <a href=\"http:\/\/pypi.python.org\/pypi\/nonblockingloghandler\/\">PyPI<\/a>, talked it up at a Python User&#8217;s Group, and I have been using it in anger for 2-3 months.<\/p>\n<p>Today, I <em>finally<\/em> got around to the <a href=\"http:\/\/www.somethinkodd.com\/oddthinking\/nonblocking-log-handler\/\">online documentation<\/a>.<\/p>\n<p>So, I can now pat myself on the back by contributing another one-person dead-end project to the Open Source Community. If just one other person finds it useful&#8230; it will have two more users than most of the software I have written in my career \ud83d\ude41<\/p>\n<p>Your feedback, as always, is very welcome.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Tying together the Nonblocking Log Handler story.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_s2mail":"","footnotes":""},"categories":[23,34,1],"tags":[],"class_list":["post-1376","post","type-post","status-publish","format-standard","hentry","category-based-on-a-true-story","category-software-development","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.somethinkodd.com\/oddthinking\/wp-json\/wp\/v2\/posts\/1376","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.somethinkodd.com\/oddthinking\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.somethinkodd.com\/oddthinking\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.somethinkodd.com\/oddthinking\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.somethinkodd.com\/oddthinking\/wp-json\/wp\/v2\/comments?post=1376"}],"version-history":[{"count":4,"href":"https:\/\/www.somethinkodd.com\/oddthinking\/wp-json\/wp\/v2\/posts\/1376\/revisions"}],"predecessor-version":[{"id":1380,"href":"https:\/\/www.somethinkodd.com\/oddthinking\/wp-json\/wp\/v2\/posts\/1376\/revisions\/1380"}],"wp:attachment":[{"href":"https:\/\/www.somethinkodd.com\/oddthinking\/wp-json\/wp\/v2\/media?parent=1376"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.somethinkodd.com\/oddthinking\/wp-json\/wp\/v2\/categories?post=1376"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.somethinkodd.com\/oddthinking\/wp-json\/wp\/v2\/tags?post=1376"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}