diff --git a/src/remote/channelSearchManager.cpp b/src/remote/channelSearchManager.cpp index c69b5f8..778db42 100644 --- a/src/remote/channelSearchManager.cpp +++ b/src/remote/channelSearchManager.cpp @@ -52,22 +52,22 @@ namespace pvAccess { // these are byte offset in a CMD_SEARCH request message // used to mangle a buffer to support incremental construction. (ick!!!) -const int ChannelSearchManager::DATA_COUNT_POSITION = PVA_MESSAGE_HEADER_SIZE + 4+1+3+16+2+1+4; -const int ChannelSearchManager::CAST_POSITION = PVA_MESSAGE_HEADER_SIZE + 4; -const int ChannelSearchManager::PAYLOAD_POSITION = 4; +static const int DATA_COUNT_POSITION = PVA_MESSAGE_HEADER_SIZE + 4+1+3+16+2+1+4; +static const int CAST_POSITION = PVA_MESSAGE_HEADER_SIZE + 4; +static const int PAYLOAD_POSITION = 4; // 225ms +/- 25ms random -const double ChannelSearchManager::ATOMIC_PERIOD = 0.225; -const int ChannelSearchManager::PERIOD_JITTER_MS = 25; +static const double ATOMIC_PERIOD = 0.225; +static const double PERIOD_JITTER_MS = 0.025; -const int ChannelSearchManager::DEFAULT_USER_VALUE = 1; -const int ChannelSearchManager::BOOST_VALUE = 1; +static const int DEFAULT_USER_VALUE = 1; +static const int BOOST_VALUE = 1; // must be power of two (so that search is done) -const int ChannelSearchManager::MAX_COUNT_VALUE = 1 << 8; -const int ChannelSearchManager::MAX_FALLBACK_COUNT_VALUE = (1 << 7) + 1; +static const int MAX_COUNT_VALUE = 1 << 8; +static const int MAX_FALLBACK_COUNT_VALUE = (1 << 7) + 1; -const int ChannelSearchManager::MAX_FRAMES_AT_ONCE = 10; -const int ChannelSearchManager::DELAY_BETWEEN_FRAMES_MS = 50; +static const int MAX_FRAMES_AT_ONCE = 10; +static const int DELAY_BETWEEN_FRAMES_MS = 50; ChannelSearchManager::ChannelSearchManager(Context::shared_pointer const & context) : @@ -94,7 +94,7 @@ void ChannelSearchManager::activate() initializeSendBuffer(); // add some jitter so that all the clients do not send at the same time - double period = ATOMIC_PERIOD + (rand() % (2*PERIOD_JITTER_MS+1) - PERIOD_JITTER_MS)/(double)1000; + double period = ATOMIC_PERIOD + double(rand())/RAND_MAX*PERIOD_JITTER_MS; Context::shared_pointer context(m_context.lock()); if (context) diff --git a/src/remote/pv/channelSearchManager.h b/src/remote/pv/channelSearchManager.h index 43b53f9..7a628bd 100644 --- a/src/remote/pv/channelSearchManager.h +++ b/src/remote/pv/channelSearchManager.h @@ -170,21 +170,6 @@ private: * m_channels mutex. */ epics::pvData::Mutex m_mutex; - - static const int DATA_COUNT_POSITION; - static const int CAST_POSITION; - static const int PAYLOAD_POSITION; - - static const double ATOMIC_PERIOD; - static const int PERIOD_JITTER_MS; - - static const int DEFAULT_USER_VALUE; - static const int BOOST_VALUE; - static const int MAX_COUNT_VALUE; - static const int MAX_FALLBACK_COUNT_VALUE; - - static const int MAX_FRAMES_AT_ONCE; - static const int DELAY_BETWEEN_FRAMES_MS; }; } diff --git a/src/server/responseHandlers.cpp b/src/server/responseHandlers.cpp index 0760179..d12f415 100644 --- a/src/server/responseHandlers.cpp +++ b/src/server/responseHandlers.cpp @@ -348,15 +348,16 @@ void ServerSearchHandler::handleResponse(osiSockAddr* responseFrom, // server discovery ping by pvlist if (allowed) { - // ~random hold-off to reduce impact of all servers responding... -#define MAX_SERVER_SEARCH_RESPONSE_DELAY_MS 100 - double period = (rand() % MAX_SERVER_SEARCH_RESPONSE_DELAY_MS)/(double)1000; + // ~random hold-off to reduce impact of all servers responding. + // in [0.05, 0.15] + double delay = double(rand())/RAND_MAX; // [0, 1] + delay = delay*0.1 + 0.05; std::tr1::shared_ptr tp(new ServerChannelFindRequesterImpl(_context, 1)); tp->set("", searchSequenceId, 0, responseAddress, true, true); TimerCallback::shared_pointer tc = tp; - _context->getTimer()->scheduleAfterDelay(tc, period); + _context->getTimer()->scheduleAfterDelay(tc, delay); } } }