{"action":"created","issue":{"url":"https://api.github.com/repos/bitcoin/bitcoin/issues/5964","labels_url":"https://api.github.com/repos/bitcoin/bitcoin/issues/5964/labels{/name}","comments_url":"https://api.github.com/repos/bitcoin/bitcoin/issues/5964/comments","events_url":"https://api.github.com/repos/bitcoin/bitcoin/issues/5964/events","html_url":"https://github.com/bitcoin/bitcoin/pull/5964","id":65980983,"number":5964,"title":"Lightweight task scheduler","user":{"login":"gavinandresen","id":331997,"avatar_url":"https://avatars.githubusercontent.com/u/331997?v=3","gravatar_id":"","url":"https://api.github.com/users/gavinandresen","html_url":"https://github.com/gavinandresen","followers_url":"https://api.github.com/users/gavinandresen/followers","following_url":"https://api.github.com/users/gavinandresen/following{/other_user}","gists_url":"https://api.github.com/users/gavinandresen/gists{/gist_id}","starred_url":"https://api.github.com/users/gavinandresen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gavinandresen/subscriptions","organizations_url":"https://api.github.com/users/gavinandresen/orgs","repos_url":"https://api.github.com/users/gavinandresen/repos","events_url":"https://api.github.com/users/gavinandresen/events{/privacy}","received_events_url":"https://api.github.com/users/gavinandresen/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/bitcoin/bitcoin/labels/Improvement","name":"Improvement","color":"E6F6D6"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2015-04-02T18:09:24Z","updated_at":"2015-04-08T15:56:34Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/bitcoin/bitcoin/pulls/5964","html_url":"https://github.com/bitcoin/bitcoin/pull/5964","diff_url":"https://github.com/bitcoin/bitcoin/pull/5964.diff","patch_url":"https://github.com/bitcoin/bitcoin/pull/5964.patch"},"body":"Threads have noticeable overhead on 32-bit systems, so using fewer threads for simple tasks is better than starting up threads willy-nilly.\r\n\r\nThe first commit implements a simple task queue class (CScheduler) which can be serviced by one or more threads.\r\n\r\nThe second and third port the networking code's DumpAddresses thread to be a task instead.\r\n\r\nPorting other threads (ThreadFlushWalletDB is a good candidate) is left as an exercise for future pull requests.\r\n\r\nThe CScheduler class was developed and tested with code here: https://github.com/gavinandresen/scheduler  (see main.cpp)\r\n\r\nI tested the ThreadImport change by running -regtest -reindex on a -regtest chain I had lying around.\r\n\r\nI tested the DumpAddresses change running with -debug=net and a hacked DEBUG_ADDRESS_INTERVAL, and made sure  I got more than one \"Flushed %d addresses to peers.dat\" in my debug.log.\r\n"},"comment":{"url":"https://api.github.com/repos/bitcoin/bitcoin/issues/comments/90958815","html_url":"https://github.com/bitcoin/bitcoin/pull/5964#issuecomment-90958815","issue_url":"https://api.github.com/repos/bitcoin/bitcoin/issues/5964","id":90958815,"user":{"login":"gavinandresen","id":331997,"avatar_url":"https://avatars.githubusercontent.com/u/331997?v=3","gravatar_id":"","url":"https://api.github.com/users/gavinandresen","html_url":"https://github.com/gavinandresen","followers_url":"https://api.github.com/users/gavinandresen/followers","following_url":"https://api.github.com/users/gavinandresen/following{/other_user}","gists_url":"https://api.github.com/users/gavinandresen/gists{/gist_id}","starred_url":"https://api.github.com/users/gavinandresen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gavinandresen/subscriptions","organizations_url":"https://api.github.com/users/gavinandresen/orgs","repos_url":"https://api.github.com/users/gavinandresen/repos","events_url":"https://api.github.com/users/gavinandresen/events{/privacy}","received_events_url":"https://api.github.com/users/gavinandresen/received_events","type":"User","site_admin":false},"created_at":"2015-04-08T15:56:34Z","updated_at":"2015-04-08T15:56:34Z","body":"Final (?) nits picked (got rid of the obsolete run from the .h, added belt&suspenders checks for empty queue, ran through clang-format again), this should be ready for merge.\r\n\r\nI also did some more testing, writing a stress-test that created 4,000 tasks serviced by 100 threads over a couple of milliseconds ( https://github.com/gavinandresen/scheduler/blob/master/main.cpp ), and all is well, including running under valgrind.\r\n\r\n"}}