MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / _should_replicate_effects

Function _should_replicate_effects

src/commands/cmd_query.c:70–104  ·  view source on GitHub ↗

checks if we should replicate command to replicas via the original GRAPH.QUERY command or via a set of effects GRAPH.EFFECT we would prefer to use effects when the number of effects is relatively small compared to query's execution time

Source from the content-addressed store, hash-verified

68// we would prefer to use effects when the number of effects is relatively small
69// compared to query's execution time
70static bool _should_replicate_effects(void)
71{
72 // GRAPH.EFFECT will be used to replicate a query when
73 // the average modification time > configuted replicate effects threshold
74 //
75 // for example:
76 // a query which ran for 10ms and performed 5 changes
77 // the average change time is 10/5 = 2ms
78 // if 2ms > configured replicate effects threshold
79 // then the query will be replicated via GRAPH.EFFECT
80 //
81 // on the other hand if a query ran for 1ms and performed 4 changes
82 // the average change timw is 1/4 = 0.25ms
83 // 0.25 < configured replicate effects threshold
84 // then the query will be replicate via GRAPH.QUERY
85
86 //--------------------------------------------------------------------------
87 // consult with configuration
88 //--------------------------------------------------------------------------
89
90 uint64_t effects_threshold;
91 Config_Option_get(Config_EFFECTS_THRESHOLD, &effects_threshold);
92
93 // compute average change time:
94 // avg modification time = query execution time / #modifications
95 double exec_time = QueryCtx_GetRuntime();
96 uint64_t n = EffectsBuffer_Length(QueryCtx_GetEffectsBuffer());
97 ASSERT(n > 0);
98 double avg_mod_time = exec_time / n;
99
100 avg_mod_time *= 1000; // convert from ms to μs microseconds
101
102 // use GRAPH.EFFECT when avg_mod_time > effects_threshold
103 return (avg_mod_time > (double)effects_threshold);
104}
105
106static bool abort_and_check_timeout
107(

Callers 1

_ExecuteQueryFunction · 0.85

Calls 4

Config_Option_getFunction · 0.85
QueryCtx_GetRuntimeFunction · 0.85
EffectsBuffer_LengthFunction · 0.85

Tested by

no test coverage detected