diff --git a/src/flow-hash.c b/src/flow-hash.c index e418a9d9e3..b08163be17 100644 --- a/src/flow-hash.c +++ b/src/flow-hash.c @@ -861,6 +861,8 @@ Flow *FlowGetExistingFlowFromHash(FlowKey *key, const uint32_t hash) return f; } +#define FLOW_GET_NEW_TRIES 5 + /** \internal * \brief Get a flow from the hash directly. * @@ -878,20 +880,17 @@ Flow *FlowGetExistingFlowFromHash(FlowKey *key, const uint32_t hash) */ static Flow *FlowGetUsedFlow(ThreadVars *tv, DecodeThreadVars *dtv) { - uint32_t idx = SC_ATOMIC_GET(flow_prune_idx) % flow_config.hash_size; + uint32_t idx = SC_ATOMIC_ADD(flow_prune_idx, FLOW_GET_NEW_TRIES) % flow_config.hash_size; uint32_t cnt = flow_config.hash_size; uint32_t tried = 0; while (cnt--) { - tried++; + if (tried++ > FLOW_GET_NEW_TRIES) + break; + if (++idx >= flow_config.hash_size) idx = 0; - if (tried >= 25) { - (void) SC_ATOMIC_ADD(flow_prune_idx, (flow_config.hash_size - cnt)); - break; - } - FlowBucket *fb = &flow_hash[idx]; if (FBLOCK_TRYLOCK(fb) != 0) @@ -960,8 +959,6 @@ static Flow *FlowGetUsedFlow(ThreadVars *tv, DecodeThreadVars *dtv) FlowUpdateState(f, FLOW_STATE_NEW); FLOWLOCK_UNLOCK(f); - - (void) SC_ATOMIC_ADD(flow_prune_idx, (flow_config.hash_size - cnt)); return f; } diff --git a/src/flow-manager.c b/src/flow-manager.c index 3b3aa3b58a..74dc7907c7 100644 --- a/src/flow-manager.c +++ b/src/flow-manager.c @@ -108,9 +108,9 @@ void FlowTimeoutsEmergency(void) /* 1 seconds */ #define FLOW_NORMAL_MODE_UPDATE_DELAY_SEC 1 #define FLOW_NORMAL_MODE_UPDATE_DELAY_NSEC 0 -/* 0.1 seconds */ +/* 0.3 seconds */ #define FLOW_EMERG_MODE_UPDATE_DELAY_SEC 0 -#define FLOW_EMERG_MODE_UPDATE_DELAY_NSEC 100000 +#define FLOW_EMERG_MODE_UPDATE_DELAY_NSEC 300000 #define NEW_FLOW_COUNT_COND 10 typedef struct FlowTimeoutCounters_ {