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

Improve containers stopping performance by handling SIGTERM (95% improvement) #627

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 10 additions & 2 deletions api/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ expressWs(app);
}
}
});
fss.chmodSync(path.join(config.data_directory, globals.data_directories.jobs), 0o711)
fss.chmodSync(
path.join(config.data_directory, globals.data_directories.jobs),
0o711
);

logger.info('Loading packages');
const pkgdir = path.join(
Expand Down Expand Up @@ -92,7 +95,12 @@ expressWs(app);
logger.debug('Calling app.listen');
const [address, port] = config.bind_address.split(':');

app.listen(port, address, () => {
const server = app.listen(port, address, () => {
logger.info('API server started on', config.bind_address);
});

process.on('SIGTERM', () => {
server.close();
process.exit(0)
});
})();
2 changes: 1 addition & 1 deletion repo/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RUN apt-get update && apt-get install -y unzip autoconf build-essential libssl-d
rm -rf /var/lib/apt/lists/* && \
update-alternatives --install /usr/bin/python python /usr/bin/python3.7 2

ADD entrypoint.sh mkindex.sh /
ADD entrypoint.sh mkindex.sh serve.py /

ENTRYPOINT ["bash","/entrypoint.sh"]
CMD ["--no-build"]
7 changes: 4 additions & 3 deletions repo/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ do
echo "Done with package $pkg"
elif [[ $CI -eq 1 ]]; then
echo "Commit SHA: $pkg"

cd ..
echo "Changed files:"
git diff --name-only $pkg^1 $pkg
Expand All @@ -52,8 +52,9 @@ echo "Index created"

if [[ $SERVER -eq 1 ]]; then
echo "Starting index server.."
python3 -m http.server
# We want the child process to replace the shell to handle signals
exec python3 /serve.py
else
echo "Skipping starting index server"
fi
exit 0
exit 0
18 changes: 18 additions & 0 deletions repo/serve.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import signal
import sys
import http.server
import socketserver

PORT = 8000

Handler = http.server.SimpleHTTPRequestHandler


def signal_handler(sig, frame):
sys.exit(0)

signal.signal(signal.SIGTERM, signal_handler)

with socketserver.TCPServer(("", PORT), Handler) as httpd:
print("serving at port", PORT)
httpd.serve_forever()