Skip to content

Commit 6bddea4

Browse files
authored
Merge pull request #3917 from hove-io/remove_instance_breaker
remove instance circuit breaker
2 parents 71739ed + 0bb711b commit 6bddea4

File tree

4 files changed

+9
-41
lines changed

4 files changed

+9
-41
lines changed

source/jormungandr/jormungandr/default_settings.py

-2
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,6 @@
137137
ISOCHRONE_DEFAULT_VALUE = os.getenv('JORMUNGANDR_ISOCHRONE_DEFAULT_VALUE', 1800) # in s
138138

139139
# circuit breaker parameters.
140-
CIRCUIT_BREAKER_MAX_INSTANCE_FAIL = 4 # max instance call failures before stopping attempt
141-
CIRCUIT_BREAKER_INSTANCE_TIMEOUT_S = 60 # the circuit breaker retries after this timeout (in seconds)
142140

143141
CIRCUIT_BREAKER_MAX_TIMEO_FAIL = 4 # max instance call failures before stopping attempt
144142
CIRCUIT_BREAKER_TIMEO_TIMEOUT_S = 60 # the circuit breaker retries after this timeout (in seconds)

source/jormungandr/jormungandr/instance.py

+6-19
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
from shapely.geos import PredicateError, ReadingError, TopologicalError
5555
from flask import g
5656
import flask
57-
import pybreaker
5857
from jormungandr import georef, schedule, realtime_schedule, ptref, street_network, fallback_modes
5958
from jormungandr.scenarios.ridesharing.ridesharing_service_manager import RidesharingServiceManager
6059
import six
@@ -139,10 +138,6 @@ def __init__(
139138
self.timezone = None # timezone will be fetched from the kraken
140139
self.publication_date = -1
141140
self.is_initialized = False # kraken hasn't been called yet we don't have geom nor timezone
142-
self.breaker = pybreaker.CircuitBreaker(
143-
fail_max=app.config.get(str('CIRCUIT_BREAKER_MAX_INSTANCE_FAIL'), 5),
144-
reset_timeout=app.config.get(str('CIRCUIT_BREAKER_INSTANCE_TIMEOUT_S'), 60),
145-
)
146141
self.georef = georef.Kraken(self)
147142
self._streetnetwork_backend_manager = streetnetwork_backend_manager
148143

@@ -722,21 +717,14 @@ def places_proximity_radius(self):
722717
instance_db = self.get_models()
723718
return get_value_or_default('places_proximity_radius', instance_db, self.name)
724719

725-
def send_and_receive(self, *args, **kwargs):
726-
"""
727-
encapsulate all call to kraken in a circuit breaker, this way we don't loose time calling dead instance
728-
"""
729-
try:
730-
return self.breaker.call(self._send_and_receive, *args, **kwargs)
731-
except pybreaker.CircuitBreakerError as e:
732-
raise DeadSocketException(self.name, self.socket_path)
733-
734-
def _send_and_receive(self, request, timeout=app.config.get('INSTANCE_TIMEOUT', 10), quiet=False, **kwargs):
720+
def send_and_receive(
721+
self, request, timeout=app.config.get('INSTANCE_TIMEOUT', 10), quiet=False, request_id=None, **kwargs
722+
):
735723
deadline = datetime.utcnow() + timedelta(milliseconds=timeout * 1000)
736724
request.deadline = deadline.strftime('%Y%m%dT%H%M%S,%f')
737725

738-
if 'request_id' in kwargs and kwargs['request_id']:
739-
request.request_id = kwargs['request_id']
726+
if request_id:
727+
request.request_id = request_id
740728
else:
741729
try:
742730
request.request_id = flask.request.id
@@ -851,8 +839,7 @@ def init(self):
851839
req.requested_api = type_pb2.METADATAS
852840
request_id = "instance_init"
853841
try:
854-
# we use _send_and_receive to avoid the circuit breaker, we don't want fast fail on init :)
855-
resp = self._send_and_receive(req, request_id=request_id, timeout=1, quiet=True)
842+
resp = self.send_and_receive(req, request_id=request_id, timeout=1, quiet=True)
856843
# the instance is automatically updated on a call
857844
if self.publication_date != pub_date:
858845
return True

source/jormungandr/jormungandr/pt_planners/common.py

+3-17
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
from __future__ import absolute_import, print_function, unicode_literals, division
3030

3131
import logging
32-
import pybreaker
3332
import zmq
3433

3534
from datetime import datetime, timedelta
@@ -60,17 +59,13 @@ def __init__(
6059
name=name, zmq_context=zmq_context, zmq_socket=zmq_socket, socket_ttl=socket_ttl
6160
)
6261
self.timeout = timeout
63-
self.breaker = pybreaker.CircuitBreaker(
64-
fail_max=app.config.get(str('CIRCUIT_BREAKER_MAX_INSTANCE_FAIL'), 5),
65-
reset_timeout=app.config.get(str('CIRCUIT_BREAKER_INSTANCE_TIMEOUT_S'), 60),
66-
)
6762

68-
def _send_and_receive(self, request, quiet=False, **kwargs):
63+
def send_and_receive(self, request, quiet=False, request_id=None, **kwargs):
6964
deadline = datetime.utcnow() + timedelta(milliseconds=self.timeout * 1000)
7065
request.deadline = deadline.strftime('%Y%m%dT%H%M%S,%f')
7166

72-
if 'request_id' in kwargs and kwargs['request_id']:
73-
request.request_id = kwargs['request_id']
67+
if request_id:
68+
request.request_id = request_id
7469
else:
7570
try:
7671
request.request_id = flask.request.id
@@ -86,15 +81,6 @@ def _send_and_receive(self, request, quiet=False, **kwargs):
8681
resp.ParseFromString(pb)
8782
return resp
8883

89-
def send_and_receive(self, *args, **kwargs):
90-
"""
91-
encapsulate all call to kraken in a circuit breaker, this way we don't lose time calling dead instance
92-
"""
93-
try:
94-
return self.breaker.call(self._send_and_receive, *args, **kwargs)
95-
except pybreaker.CircuitBreakerError:
96-
raise DeadSocketException(self.name, self._zmq_socket)
97-
9884
def clean_up_zmq_sockets(self):
9985
for socket in self._sockets:
10086
socket.setsockopt(zmq.LINGER, 0)

source/jormungandr/tests/integration_tests_settings.py

-3
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@
6565
}
6666
}
6767

68-
# circuit breaker parameters, for the tests by default we don't want the circuit breaker
69-
CIRCUIT_BREAKER_MAX_INSTANCE_FAIL = 99999
70-
CIRCUIT_BREAKER_INSTANCE_TIMEOUT_S = 1
7168

7269
GRAPHICAL_ISOCHRONE = True
7370
HEAT_MAP = True

0 commit comments

Comments
 (0)