feat/58 - simplify complex logic
This commit is contained in:
@@ -127,7 +127,7 @@ class DataMessageHandler:
|
||||
self.backpressure_handler.increase_current_load()
|
||||
await self.backpressure_handler.check_overload_condition()
|
||||
logging_info(
|
||||
f"PARALLEL: Current Capacity [{self.backpressure_handler.current_load}] of [{self.backpressure_handler.maximum_load}]"
|
||||
f"PARALLEL: Current Capacity [{self.backpressure_handler.current_availability}] of [{self.backpressure_handler.max_availability}]"
|
||||
)
|
||||
if message.reply_to:
|
||||
self.reply_to = message.reply_to
|
||||
@@ -156,7 +156,6 @@ class DataMessageHandler:
|
||||
logging_error(f"Request handler: {e}")
|
||||
|
||||
self.backpressure_handler.decrease_current_load()
|
||||
await self.backpressure_handler.check_overload_condition()
|
||||
|
||||
async def reconstitute_data_message(
|
||||
self, message: AbstractIncomingMessage
|
||||
|
||||
@@ -64,6 +64,7 @@ class AMQService:
|
||||
)
|
||||
self.backpressure_thread: Optional[Thread] = None
|
||||
self.backpressure_handler: Optional[BackpressureHandler] = None
|
||||
self.maximum_availability = -1
|
||||
|
||||
# =======================================================================
|
||||
# =======================================================================
|
||||
@@ -87,21 +88,28 @@ class AMQService:
|
||||
"""
|
||||
Send Backpressure event to the Management Service. The Backpressure logic determines the type of the event
|
||||
based on the current_availability and maximum values.
|
||||
- OVERLOAD event is triggered immediately when the current_availability value exceeds the maximum threshold, which is
|
||||
typically set to 80% of the maximum value.
|
||||
- IDLE event is triggered when the current_availability value drops below 20% of the maximum value and remains there for
|
||||
a IDLE_WINDOW period of time (see BackpressureHandler).
|
||||
- OVERLOAD event is triggered immediately when the current_availability value is below threshold
|
||||
typically set to 10% of the maximum value, or 0 if no maximum is provided.
|
||||
- IDLE event is triggered when the current_availability value exeeds 80% of the maximum value or is greater
|
||||
than 0 if no maximum is provided.
|
||||
- UPDATE event is sent if neither OVERLOAD nor IDLE conditions are met, indicating that the backpressure is
|
||||
within acceptable limits.
|
||||
:param current_availability: Currently available caopacity.
|
||||
:param current_availability: Currently available capacity.
|
||||
:param maximum: Maximum value of the backpressure metric. If undefined or set to lt 0 (e.g. -1),
|
||||
the maximum is than hgdetermined from max value of current_availability seen over the time.
|
||||
the maximum is than determined from max value of current_availability seen over the time.
|
||||
"""
|
||||
if self.backpressure_handler is not None:
|
||||
# watch maximum & current value to always have some valid maximum reference
|
||||
if maximum < 0:
|
||||
maximum = self.amq_configuration.backpressure.threshold_load
|
||||
if current_availability > self.maximum_availability:
|
||||
self.maximum_availability = current_availability
|
||||
else:
|
||||
if maximum > self.maximum_availability:
|
||||
self.maximum_availability = maximum
|
||||
asyncio.run_coroutine_threadsafe(
|
||||
self.backpressure_handler.update_backpressure_value(current_availability, maximum),
|
||||
self.backpressure_handler.update_backpressure_value(
|
||||
current_availability, maximum if maximum > 0 else self.maximum_availability
|
||||
),
|
||||
loop=self.backpressure_handler.loop,
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user