ZMQ: add options to configure outbound message high water mark, aka SNDHWM
This is my attempt at https://github.com/bitcoin/bitcoin/pull/13315
ZMQ: add options to configure outbound message high water mark, aka SNDHWM
This is my attempt at https://github.com/bitcoin/bitcoin/pull/13315
442@@ -443,11 +443,19 @@ void SetupServerArgs()
443 gArgs.AddArg("-zmqpubhashtx=<address>", "Enable publish hash transaction in <address>", false, OptionsCategory::ZMQ);
444 gArgs.AddArg("-zmqpubrawblock=<address>", "Enable publish raw block in <address>", false, OptionsCategory::ZMQ);
445 gArgs.AddArg("-zmqpubrawtx=<address>", "Enable publish raw transaction in <address>", false, OptionsCategory::ZMQ);
446+ gArgs.AddArg("-zmqpubhashblockhwm=<n>", strprintf("Set publish hash block outbound message high water mark (default: %d)", DEFAULT_ZMQ_SNDHWM), false, OptionsCategory::ZMQ);
447+ gArgs.AddArg("-zmqpubhashtxhwm=<n>", strprintf("Set publish hash transaction outbound message high water mark (default: %d)", DEFAULT_ZMQ_SNDHWM), false, OptionsCategory::ZMQ);
448+ gArgs.AddArg("-zmqpubrawblockhwm=<n>", strprintf("Set publish raw block outbound message high water mark (default: %d)", DEFAULT_ZMQ_SNDHWM), false, OptionsCategory::ZMQ);
449+ gArgs.AddArg("-zmqpubrawtxhwm=<n>", strprintf("Set publish raw transaction outbound message high water mark (default: %d)", DEFAULT_ZMQ_SNDHWM), false, OptionsCategory::ZMQ);
-zmqpubrawtx=<address>;hwm=<hwm>
perhaps?
getzmqnotifications
.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
Reviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
99@@ -98,11 +100,11 @@ bool CZMQNotificationInterface::Initialize()
100 CZMQAbstractNotifier *notifier = *i;
101 if (notifier->Initialize(pcontext))
102 {
103- LogPrint(BCLog::ZMQ, " Notifier %s ready (address = %s)\n", notifier->GetType(), notifier->GetAddress());
104+ LogPrint(BCLog::ZMQ, "zmq: Notifier %s ready (address = %s)\n", notifier->GetType(), notifier->GetAddress());
@promag there can only be one of each of the notification types and each can have only one address. @mruddy right, at some point I was going to add support for multiple notifications of the same type but for some reason I don’t remember why I quit that, so that got me confused.
My suggestion for the long term is to extend the existing argument, like:
0-zmqpubhashtx=tcp://127.0.0.1:28332,hwm=20000,foo=bar,...
And this would allow multiple pubhashtx with different high water mark and other options.
Given the above, for now, a global/default hwm looks enough, and the above could be implemented later.
40@@ -39,6 +41,7 @@ class CZMQAbstractNotifier
41 void *psocket;
42 std::string type;
43 std::string address;
44+ int outbound_message_high_water_mark; // aka SNDHWM
outbound_message_high_water_mark
not initialized in the constructor?
29@@ -28,6 +30,12 @@ class CZMQAbstractNotifier
30 void SetType(const std::string &t) { type = t; }
31 std::string GetAddress() const { return address; }
32 void SetAddress(const std::string &a) { address = a; }
33+ int GetOutboundMessageHighWaterMark() const { return outbound_message_high_water_mark; }
34+ void SetOutboundMessageHighWaterMark(const int sndhwm) {
35+ if ((sndhwm >= 0) && (sndhwm <= std::numeric_limits<int>::max())) {
02018-09-25 21:25:16 clang(pr=14060): zmq/zmqabstractnotifier.h:35:38: warning: result of comparison 'const int' <= 2147483647 is always true [-Wtautological-type-limit-compare]
Use static_assert
instead?
ok, i’ll just check it like zmq checks it: https://github.com/zeromq/libzmq/blob/master/src/options.cpp#L310-L315
also rebased. thanks!
58@@ -59,6 +59,7 @@ CZMQNotificationInterface* CZMQNotificationInterface::Create()
59 CZMQAbstractNotifier *notifier = factory();
60 notifier->SetType(entry.first);
61 notifier->SetAddress(address);
62+ notifier->SetOutboundMessageHighWaterMark(gArgs.GetArg(arg + "hwm", CZMQAbstractNotifier::DEFAULT_ZMQ_SNDHWM));
02018-09-25 21:25:16 clang(pr=14060): zmq/zmqnotificationinterface.cpp:62:61: warning: implicit conversion loses integer precision: 'int64_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
bitcoind
side when used? If so, that needs clear documentation.
Will this make ZMQ publishing blocking on the
bitcoind
side when used? If so, that needs clear documentation.
No, it will not. To add more color, without this PR, the SNDHWM is 1000. These new options just allow changing that value to something else. The drop/block behavior does not change. The motivation for this change was dropped messages. And from the ZMQ API docs, we see that the documented behavior is to drop (which is what we want, and what was experienced as the motivation): ‘When a ZMQ_PUB socket enters the mute state due to having reached the high water mark for a subscriber, then any messages that would be sent to the subscriber in question shall instead be dropped until the mute state ends."