Skip to content

Commit

Permalink
[PERF]: Optimized docker image (#1613)
Browse files Browse the repository at this point in the history
## Description of changes

*Summarize the changes made by this PR.*
 - Improvements & Bug fixes
	 - Removed the re-download of hnsw in docker entrypoint
- Removed build dependencies in final image to reduce size (by about
100M)
         - Added flag for rebuilding hnsw lib from source
         - Added docs how to build in image with hardware-optimized hnsw

## Test plan
*How are these changes tested?*

- [x] Tests pass locally with `pytest` for python, `yarn test` for js

## Documentation Changes
Example of building AVX-optimized image added under `examples/`.
  • Loading branch information
tazarov authored Jan 22, 2024
1 parent b5dc65f commit d22b87b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
21 changes: 9 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
FROM python:3.10-slim-bookworm as builder

FROM python:3.11-slim-bookworm AS builder
ARG REBUILD_HNSWLIB
RUN apt-get update --fix-missing && apt-get install -y --fix-missing \
build-essential \
gcc \
g++ && \
rm -rf /var/lib/apt/lists/*
g++ \
cmake \
autoconf && \
rm -rf /var/lib/apt/lists/* && \
mkdir /install

RUN mkdir /install
WORKDIR /install

COPY ./requirements.txt requirements.txt

RUN pip install --no-cache-dir --upgrade --prefix="/install" -r requirements.txt
RUN if [ "$REBUILD_HNSWLIB" = "true" ]; then pip install --no-binary :all: --force-reinstall --no-cache-dir --prefix="/install" chroma-hnswlib; fi

FROM python:3.10-slim-bookworm as final

RUN apt-get update --fix-missing && apt-get install -y --fix-missing \
build-essential \
gcc \
g++ && \
rm -rf /var/lib/apt/lists/*
FROM python:3.11-slim-bookworm AS final

RUN mkdir /chroma
WORKDIR /chroma
Expand Down
2 changes: 0 additions & 2 deletions bin/docker_entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/bin/bash

echo "Rebuilding hnsw to ensure architecture compatibility"
pip install --force-reinstall --no-cache-dir chroma-hnswlib
export IS_PERSISTENT=1
export CHROMA_SERVER_NOFILE=65535
exec uvicorn chromadb.app:app --workers 1 --host 0.0.0.0 --port 8000 --proxy-headers --log-config chromadb/log_config.yml --timeout-keep-alive 30
10 changes: 10 additions & 0 deletions examples/advanced/hadrware-optimized-image.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Building Hardware Optimized ChromaDB Image

The default Chroma DB image comes with binary distribution of hnsw lib which is not optimized to take advantage of
certain CPU architectures (Intel-based) with AVX support. This can be improved by building an image with hnsw rebuilt
from source. To do that run:

```bash
docker build -t chroma-test1 --build-arg REBUILD_HNSWLIB=true --no-cache .
```

0 comments on commit d22b87b

Please sign in to comment.