Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fault tolerance #82

Merged
merged 9 commits into from
Nov 20, 2020
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ All the configurations are grouped in *sections* and some of them can vary depen
- `DashboardURL`: Sets the url where the frontend is running. Unless you are using a custom domain, you should keep this value as https://beta.lanthorn.ai/.
- `EnableSlackNotifications`: A boolean parameter to enable/disable the Slack integration for notifications and daily reports. We recommend not editing this parameter directly and manage it from the [UI](https://beta.lanthorn.ai) to configure your workspace correctly.
- `SlackChannel`: Configures the slack channel used by the notifications. The chosen slack channel must exist in the configured workspace.
- `OccupancyAlertsMinInterval`: Sets the desired interval (in seconds) between occupancy alerts.
- `MaxThreadRestarts`: Defines the number of restarts allowed per thread.

- `[Api]`
- `Host`: Configures the host IP of the processor's API (inside docker). We recommend don't change that value and keep it as *0.0.0.0*.
Expand Down
2 changes: 1 addition & 1 deletion amd64-usbtpu.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
ENV DEV_ALLOW_ALL_ORIGINS=true
ENV AWS_SHARED_CREDENTIALS_FILE=/repo/.aws/credentials
ENV AWS_CONFIG_FILE=/repo/.aws/config
ENV CONFIG_FILE=config-coral.ini

RUN cd / && apt-get update && apt-get install -y git python3-edgetpu && git clone \
https://github.com/google-coral/project-posenet.git && sed -i 's/sudo / /g' \
/project-posenet/install_requirements.sh && sh /project-posenet/install_requirements.sh
ENV PYTHONPATH=$PYTHONPATH:/project-posenet
ENV CONFIG_FILE=config-coral.ini

COPY . /repo
WORKDIR /repo
Expand Down
2 changes: 2 additions & 0 deletions config-coral.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ EnableSlackNotifications = no
SlackChannel = lanthorn-notifications
; OccupancyAlertsMinInterval time is measured in seconds (if interval < 0 then no occupancy alerts are triggered)
OccupancyAlertsMinInterval = 180
MaxThreadRestarts = 5


[API]
Host = 0.0.0.0
Expand Down
1 change: 1 addition & 0 deletions config-jetson.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ EnableSlackNotifications = no
SlackChannel = lanthorn-notifications
; OccupancyAlertsMinInterval time is measured in seconds (if interval < 0 then no occupancy alerts are triggered)
OccupancyAlertsMinInterval = 180
MaxThreadRestarts = 5

[API]
Host = 0.0.0.0
Expand Down
2 changes: 2 additions & 0 deletions config-x86-gpu.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ DashboardURL = http://0.0.0.0:8000
ScreenshotsDirectory = /repo/data/processor/static/screenshots
EnableSlackNotifications = no
SlackChannel = lanthorn-notifications
OccupancyAlertsMinInterval = 180
MaxThreadRestarts = 5

[Area_0]
Id = area0
Expand Down
1 change: 1 addition & 0 deletions config-x86-openvino.ini
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ EnableSlackNotifications = no
SlackChannel = lanthorn-notifications
; OccupancyAlertsMinInterval time is measured in seconds (if interval < 0 then no occupancy alerts are triggered)
OccupancyAlertsMinInterval = 180
MaxThreadRestarts = 5

[Area_0]
Id = area0
Expand Down
1 change: 1 addition & 0 deletions config-x86.ini
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ EnableSlackNotifications = no
SlackChannel = lanthorn-notifications
; OccupancyAlertsMinInterval time is measured in seconds (if interval < 0 then no occupancy alerts are triggered)
OccupancyAlertsMinInterval = 180
MaxThreadRestarts = 5

[Area_0]
Id = area0
Expand Down
5 changes: 2 additions & 3 deletions coral-dev-board.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,14 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
ENV DEV_ALLOW_ALL_ORIGINS=true
ENV AWS_SHARED_CREDENTIALS_FILE=/repo/.aws/credentials
ENV AWS_CONFIG_FILE=/repo/.aws/config
ENV CONFIG_FILE=config-coral.ini


RUN cd / && apt-get update && apt-get install -y git python3-edgetpu && git clone \
https://github.com/google-coral/project-posenet.git && sed -i 's/sudo / /g' \
/project-posenet/install_requirements.sh && sh /project-posenet/install_requirements.sh
ENV PYTHONPATH=$PYTHONPATH:/project-posenet

ENV CONFIG_FILE=config-coral.ini
# Also if you use opencv: LD_PRELOAD="/usr/lib/aarch64-linux-gnu/libgomp.so.1.0.0"

COPY . /repo
WORKDIR /repo
HEALTHCHECK --interval=30s --retries=2 --start-period=15s CMD bash healthcheck.bash
Expand Down
9 changes: 6 additions & 3 deletions libs/area_threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,20 @@ def __init__(self, config, area):

def run(self):
self.engine = AreaEngine(self.config, self.area)
restarts = 0
max_restarts = int(self.config.get_section_dict("App")["MaxThreadRestarts"])
while True:
try:
self.engine.process_area()
except Exception as e:
logging.error(e, exc_info=True)
logging.info(f"Exception processing area {self.area['name']}")
if restarts == max_restarts:
raise e
# Sleep the thread for 5 seconds and try to process the area again
time.sleep(5)
logging.info(f"Exception processing area {self.area['name']}")
logging.info("Restarting the area processing")

self.engine.process_area()
restarts += 1

def stop(self):
self.engine.stop_process_area()
Expand Down
7 changes: 6 additions & 1 deletion libs/engine_threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,20 @@ def __init__(self, config, source, live_feed_enabled=True):

def run(self):
self.engine = CvEngine(self.config, self.source['section'], self.live_feed_enabled)
restarts = 0
max_restarts = int(self.config.get_section_dict("App")["MaxThreadRestarts"])
while True:
try:
self.engine.process_video(self.source['url'])
except Exception as e:
logging.error(e, exc_info=True)
logging.info(f"Exception processing video for source {self.source['name']}")
if restarts == max_restarts:
pgrill marked this conversation as resolved.
Show resolved Hide resolved
raise e
# Sleep the thread for 5 seconds and try to process the video again
time.sleep(5)
logging.info(f"Exception processing video for source {self.source['name']}")
logging.info("Restarting the video processing")
restarts += 1

def stop(self):
self.engine.stop_process_video()
Expand Down
2 changes: 1 addition & 1 deletion x86.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ ENV AWS_SHARED_CREDENTIALS_FILE=/repo/.aws/credentials
ENV AWS_CONFIG_FILE=/repo/.aws/config
ENV CONFIG_FILE=config-x86.ini


COPY . /repo
WORKDIR /repo

HEALTHCHECK --interval=30s --retries=2 --start-period=15s CMD bash healthcheck.bash
CMD supervisord -c supervisord.conf -n