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

add whisper to autoscaler #652

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ansible/build-gpu-oracle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@
# docker pull most recent running version of skynet and whisper
- { role: "gpu-docker-pull", tags: "gpu-docker", gpu_docker_type: "skynet" }
- { role: "gpu-docker-pull", tags: "gpu-docker", gpu_docker_type: "whisper" }
- { role: "streaming-whisper", tags: "gpu-docker", gpu_docker_type: "whisper" }
- { role: "autoscaler-sidecar", tags: "autoscaler-sidecar",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This role is already included in the base image that GPU comes from, so no need to install it here.

autoscaler_instance_type: "streaming-whisper", autoscaler_install_flag: true, autoscaler_configure_flag: false, jitsi_autoscaler_sidecar: true}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a shared image for both skynet ande whisper, so we wouldn't want to set the instance type here.

- { role: "clean-system", tags: "clean-system, build" }
3 changes: 3 additions & 0 deletions ansible/roles/autoscaler-sidecar/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ autoscaler_force_shutdown_command_by_type:
'jigasi': 'service jigasi stop'
'sip-jibri': 'service jibri stop'
'nomad': 'nomad node drain -self -enable -force -detach -yes'
'streaming-whisper': 'nomad node drain -self -enable -force -detach -yes'
autoscaler_git_repo: https://github.com/jitsi/jitsi-autoscaler-sidecar.git
autoscaler_graceful_shutdown_script: "{{
autoscaler_graceful_shutdown_scripts[autoscaler_instance_type]
Expand All @@ -26,6 +27,7 @@ autoscaler_graceful_shutdown_scripts:
'jigasi': /usr/local/bin/graceful-shutdown-wrapper-jigasi.sh
'sip-jibri': /opt/jitsi/jibri/wait_graceful_shutdown.sh
'nomad': /usr/local/bin/nomad_graceful_shutdown.sh
'streaming-whisper': /usr/local/bin/streaming-whisper-graceful-shutdown.sh
autoscaler_graceful_shutdown_wrapper: /usr/local/bin/graceful_shutdown_wrapper.sh
autoscaler_group: "default"
autoscaler_groupname: jsidecar
Expand Down Expand Up @@ -80,6 +82,7 @@ autoscaler_stats_retrieve_urls:
'jibri': http://localhost:2222/jibri/api/v1.0/health
'jigasi': http://localhost:8788/about/stats
'sip-jibri': http://localhost:2222/jibri/api/v1.0/health
'streaming-whisper': http://localhost:8003/state
autoscaler_status_url: "https://{{ autoscaler_server_host }}/sidecar/status"
autoscaler_shutdown_url: "https://{{ autoscaler_server_host }}/sidecar/shutdown"
autoscaler_terminate_script: '/usr/local/bin/terminate_instance.sh'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env bash

# Sets the server to drain mode and waits for all the connections to be closed before exiting
# with code 0 (clean shutdown). If the connections are not closed within the specified time,
# the script will exit with code 1 (dirty) and the autoscaler will shut down the instance anyway.

# It takes two parameters: WAIT_SECONDS and STATE_URL
# WAIT_SECONDS: Seconds to wait for the server to enter drain mode and close all connections.
# Defaults to 100.
# STATE_URL: The URL of the whisper state endpoint. Defaults to http://localhost:8003/state.

# Example usage: ./shutdown_script.sh 100 http://localhost:8003/state


WAIT_SECONDS=100
STATE_URL="http://localhost:8003/state"

[[ -z $1 ]] && echo "Parameter WAIT_SECONDS not set, using default $WAIT_SECONDS" || WAIT_SECONDS=$1
[[ -z $2 ]] && echo "Parameter STATE_URL not set, using default $STATE_URL" || STATE_URL=$2

echo "Waiting for $WAIT_SECONDS seconds for the server to enter drain mode and close all connections."

START_TIME=$(date +%s)

while true; do
RESPONSE=$(curl -s $STATE_URL)
WHISPER_STATE=$(echo $RESPONSE | jq -r '.state')
ACTIVE_CONNECTIONS=$(echo $RESPONSE | jq -r '.connections')
if [[ $WHISPER_STATE != "drain" ]]; then
echo "Setting server in drain mode."
curl -s -XPOST $STATE_URL -d '{"state": "drain"}' | jq -r '.request_status'
else
echo "Server is in drain mode. Waiting for $ACTIVE_CONNECTIONS connections to be closed before shutting down"
if [[ $ACTIVE_CONNECTIONS -eq 0 ]]; then
echo "All connections are closed. Shutting down the instance."
exit 0
fi
fi
CURRENT_TIME=$(date +%s)
ELAPSED_TIME=$((CURRENT_TIME - START_TIME))
if [[ $ELAPSED_TIME -gt $WAIT_SECONDS ]]; then
break
fi
sleep 2
done

echo "Server did not close all connections within $WAIT_SECONDS seconds. Shutting down anyway."
exit 1
13 changes: 13 additions & 0 deletions ansible/roles/streaming-whisper/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
- name: Install dependencies
ansible.builtin.package:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine to include these, but just FYI they should both be already installed in the base image so this will be a no-op.

name:
- jq
- curl
state: latest

- name: Copy graceful shutdown script
ansible.builtin.copy:
src: streaming-whisper-graceful-shutdown.sh
dest: /usr/local/bin/streaming-whisper-graceful-shutdown.sh
mode: 0755
owner: root