Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Drop IO priority to idle while reading blocks for getblock requests #9245

Open
wants to merge 2 commits into
from

Conversation

Projects
None yet
8 participants
Member

luke-jr commented Nov 30, 2016

No description provided.

src/util.h
@@ -131,6 +131,49 @@ void OpenDebugLog();
void ShrinkDebugFile();
void runCommand(const std::string& strCommand);
+#ifdef HAVE_IOPRIO_SYSCALL
@laanwj

laanwj Nov 30, 2016

Owner

Please move this to a new include file util_ioprio.h.

Owner

laanwj commented Nov 30, 2016

Concept ACK. Though not very happy to introduce platform-specific voodoo - we only just got rid of thread priority manipulation. But it may be worth the hassle, I don't know.

Can we quantify whether this works or not somehow?

Member

gmaxwell commented Nov 30, 2016

This will also delay other processing, in particular block relay-- at least until the handling is made more concurrent-- no? Not a reason to not do it, but maybe a reason to not do it by default for everyone.

I second the need to quantify this-- I could imagine it making for a big usability improvement. ... or not mattering at all. If the former, I want it... if the latter...

Member

luke-jr commented Nov 30, 2016

Whenever I restart my node lately, I find myself eventually manually ioniceing the entire process as it slows down other things monitoring it in iotop. I can't be sure it's sending out old blocks, but I can't imagine what else it'd be spending so much time reading... :/

Added Mac and Windows support for completeness.

ryanofsky approved these changes Nov 30, 2016 edited

ACK 6430b92 (after adding missing #includes)

src/utilioprio.cpp
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#ifdef HAVE_IOPRIO_SYSCALL
@ryanofsky

ryanofsky Nov 30, 2016

Contributor

Needs #include "config/bitcoin-config.h" to prevent link errors.

+// Distributed under the MIT software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#ifndef BITCOIN_UTIL_IOPRIO_H
@ryanofsky

ryanofsky Nov 30, 2016

Contributor

Should add #include "config/bitcoin-config.h"

src/utilioprio.h
+#define IOPRIO_IDLER(actually_idle) ioprio_idler ioprio_idler_(actually_idle)
+
+#else
+#define ioprio_get() (-1)
@ryanofsky

ryanofsky Nov 30, 2016

Contributor

It doesn't seem like it should be necessary to declare these if the ioprio_idler class isn't around to call them.

@luke-jr

luke-jr Nov 30, 2016

Member

We can simplify some of the other stuff (move the logic into the class itself) if low-level access is undesired, but for now it's too early to know if these won't be needed IMO.

src/utilioprio.h
+#ifdef WIN32
+bool ioprio_set_file_idle(FILE *);
+#else
+#define ioprio_set_file_idle(f) (false)
@ryanofsky

ryanofsky Nov 30, 2016

Contributor

Maybe change this to ((void)false) to prevent a compiler warning:

main.cpp:1673:12: warning: statement has no effect [-Wunused-value]
     ioprio_set_file_idle(filein.Get());
Member

fanquake commented Dec 1, 2016

Travis failure:

'../../src/'`utilioprio.cpp
In file included from ../../src/utilioprio.cpp:9:0:
../../src/utilioprio.h: In destructor ‘ioprio_idler::~ioprio_idler()’:
../../src/utilioprio.h:42:51: error: ‘LogPrintf’ was not declared in this scope
             LogPrintf("failed to restore ioprio\n");
Member

luke-jr commented Dec 1, 2016

Looks like to make the Windows part work, we need to bump _WIN32_WINNT to 0x0600 which means it will only run on Vista or newer. AFAIK this is okay(?), but I'm going to leave it for a separate PR...

Contributor

rebroad commented Dec 19, 2016

I like this (concept ACK) although I wonder what the impact is on the p2p network as a whole if everyone ran this.

Looks like to make the Windows part work, we need to bump _WIN32_WINNT to 0x0600 which means it will only run on Vista or newer.

There are win32 and win64 builds. Can't this just be enabled on the win64 build only?

Owner

laanwj commented Mar 13, 2017

Looks like to make the Windows part work, we need to bump _WIN32_WINNT to 0x0600 which means it will only run on Vista or newer. AFAIK this is okay(?), but I'm going to leave it for a separate PR...

Isn't Vista the version after Windows XP? As we dropped support for Windows XP in 0.13, it seems that requiring Vista for 0.15 is fine.

There are win32 and win64 builds. Can't this just be enabled on the win64 build only?

Could be done, but it'd be confusing to couple those. The low-end systems running 32-bit versions would probably need this more.

Member

luke-jr commented Aug 21, 2017

Rebased...

Contributor

TheBlueMatt commented Aug 21, 2017

Hmm, I dont think this is really the best idea as long as our message processing is still single-threaded. Really we need to refactor stuff so that block reading is async and the network processing can continue for other peers while we're serving blocks for peers in IBD, otherwise we may block receiving a new block longer than required.

Member

luke-jr commented Aug 21, 2017

That's somewhat independent from this issue. If users need to shut off their node to use their computer, the delay for processing a new block will be even longer.

Contributor

ryanofsky commented Oct 12, 2017

@TheBlueMatt @luke-jr, maybe a compromise would be to make this behavior configurable, and perhaps to default to dropping priority if user is running bitcoin-qt on a desktop.

Contributor

TheBlueMatt commented Nov 10, 2017

Another approach which might be simpler would be to have the validation.h-exposed versions of ReadBlockFromDisk drop io priority so that net_processing will use low priority when answering remote-node queries but connecting blocks will not. With 0.15 I/O when doing initial sync is somewhat better, so this may also be less of an issue now unless the user is running with -peerbloomfilters.

Member

luke-jr commented Nov 11, 2017

@TheBlueMatt That's exactly what this already does... priority is only dropped when serving peers, not when connecting blocks.

Contributor

TheBlueMatt commented Nov 11, 2017

@luke-jr I was referring to the possibility of not exposing a priority flag in validation.h's API - that seems a bit overkill IMO, as evidenced by the fact that there are now two ReadBlockFromDisk calls in net_processing which dont get the low-priority flag :p. Though that would also result in RPC ReadBlockFromDisk calls getting de-prioritized.

More importantly, I'm curious how much we need this anymore - it seems most of the complaints about I/O usage were primarily due to 0.13.1 preferential peering...On systems where your I/O is severely limited, I both don't know how much this will help (in my experience Linux' ionice is mostly worthless when it comes to desktop latency) and don't know if its not better to direct people towards maxuploadtarget or peerbloomfilters so as to avoid simply slowing down your peers because your I/O is too slow.

Member

luke-jr commented Nov 11, 2017

Before writing this, I generally ionice'd the entire bitcoind process to maintain system usability.

Contributor

TheBlueMatt commented Nov 16, 2017

Concept ACK. You need to mark the other ReadBlockFromDisks in net_processing low-priority as well.

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