Skip to content

Commit

Permalink
Reduce memory usage for containerized deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
plengauer authored Mar 23, 2024
1 parent 8ff6342 commit 19bab86
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Deployment/Containerized/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: philbot-containerized
Provides: philbot-deployment
Version: 2.9.5
Version: 2.10.0
Architecture: all
Depends: bash, debconf, coreutils, util-linux, findutils, parallel, awk, grep, cron, wget, curl, docker.io, iptables-persistent, jq, opentelemetry-shell (>= 2.6.1)
Conflicts: philbot-baremetal, philbot-k8s
Expand Down
8 changes: 7 additions & 1 deletion Deployment/Containerized/usr/bin/philbot_start
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,32 @@ start() {
docker start philbot-$name
}

start selfmonitoring selfmonitoring --mount type=bind,source=/var/lib/philbot/collector.yaml,target=/etc/otelcol/config.yaml
start selfmonitoring selfmonitoring --memory=25m --mount type=bind,source=/var/lib/philbot/collector.yaml,target=/etc/otelcol/config.yaml

start voice voice \
--memory=150m \
--env MEMORY_LIMIT=$((1024*1024*100))
--env PORT=12345 \
--env STATE_STORAGE_DIRECTORY=/sessions \
--mount type=bind,source=/var/lib/philbot/voice_sessions,target=/sessions \
--env CACHE_DIRECTORY=/cache \
--mount type=bind,source=/var/lib/philbot/audio_cache,target=/cache

start backend backend \
--memory=250m \
--env PORT=8080 \
--env VOICE_PORT=12345 \
--env MEMORY_DIRECTORY=/memory \
--mount type=bind,source=/var/lib/philbot/memory,target=/memory

start discordgateway2httpmaster discordgateway2httpmaster \
--memory=150m \
--env PORT=7999

for shard_index in $(seq 0 $(($SHARD_COUNT-1)))
do
start discordgateway2http_$shard_index discordgateway2http \
--memory=50m \
--env SHARD_INDEX=auto --env SHARD_COUNT=auto \
--env BASE_PORT=8081 \
--env SHARDS_MASTER_PORT=7999 \
Expand All @@ -57,6 +62,7 @@ do
done

start scheduler scheduler \
--memory=50m \
--env CONFIG_FILE=/config.properties \
--mount type=bind,source=/var/lib/philbot/config.properties.scheduler,target=/config.properties,readonly

Expand Down
4 changes: 4 additions & 0 deletions Voice/philbot-voice/voice.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import requests
import subprocess
import websocket
import resource
from flask import Flask, request, Response, send_file
import yt_dlp
import opentelemetry
Expand Down Expand Up @@ -1128,6 +1129,9 @@ def cleanup_loop():
time.sleep(60)

def main():
memory_limit = int(os.environ.get('MEMORY_LIMIT', str(0)))
if memory_limit > 0:
resource.setrlimit(resource.RLIMIT_AS, (memory_limit, memory_limit))
if not pyogg.PYOGG_OPUS_AVAIL or not pyogg.PYOGG_OPUS_FILE_AVAIL:
print('VOICE not ready (opus not available)')
exit(1)
Expand Down
2 changes: 1 addition & 1 deletion Voice/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "philbot-voice"
version = "2.2.1"
version = "2.3.0"
description = ""
authors = ["philipp.lengauer <[email protected]>"]
packages = [{include = "philbot-voice"}]
Expand Down

0 comments on commit 19bab86

Please sign in to comment.