By default the Visionbox uses a local binary file to store collections. If you want to have multiple Visionbox instances share one backend collection or if you want to enroll new images past a certain scale using a database backend might be a better option for you. This guide will explain how to do that. We'll be using docker compose to spin up a memsql and a visionbox container.
Let's get started.
Copy the following text into a file named visionbox-with-memsql-docker-compose.json
.
Copy the following text into a file named .env and fill in your
- Trueface Token
- MemSQL License key which is free for Databases under 128GB
- Database password of your choice
Start the containers
Keep in mind that the Visionbox container will try to connect to the DB with your password but the password hasn't been set on the Database yet. That's the next command after this one but until you've run that command you will see an error looping on your docker log output.
Set the password on the MemSQL Database
Now that the password is set your visionbox container (which has been restarting in the background) will be able to connect to the Database.
Send your requests to the Load Balancer for distribution
The load balancer listens on port 4000 and distributes requests across the visionbox instances in the backend. So you can send your requests to http://localhost:4000/enroll
for example.
You can now use the /enroll and /identify endpoints as you normally would or if you don't want to copy that code, using our Postman collection.
Please keep in mind the port now 4000 and not 8080 like in those examples so in the python example linked above you would replace the line which says
With
See what's going on in the database
To issue database commands directly, for example to change a label name or delete a feature you can now connect your mysql client (MemSQL is just MySQL with some additional vector math functions).
How is this getting load balanced?
The docker compose file uses a load balancer called traefik, it will distribute traffic across your visionbox instances following a round-robin schedule meaning the first request will go to node 1, the second to node 2. The fifth request will be sent to node 1 again.
You can check the status of your nodes on traefik's web interface by pointing a web browser at http://localhost:4001