Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker tmpfs seems to have no effect on postgresql

I have a Postgres database inside a docker container against which I run django tests. I want to improve the speed of the tests. The easiest way to do this (it seems to me) is to move postgres data into tmpfs volume.

Here's what I did:

docker run --name my_tfmps_test -d -p 5432:5432 \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=postgres \
-e POSTGRES_DB=my_database \
-e PGDATA=/var/lib/postgresql/data \
--tmpfs /var/lib/postgresql/data \
library/postgres

Because I specified --tmpfs I expect the tests run significantly faster. Unfortunately this is not the case. The speed of the tests remains exactly on the same level (give or take 5%).

My questions is: why did the speed of the tests did not change? And what can I do about it ?

Extra info:

  • MacOS 10.13.6
  • reference https://docs.docker.com/storage/tmpfs/
like image 930
Vladimir S. Avatar asked Sep 11 '18 14:09

Vladimir S.


People also ask

How does Docker integrate with PostgreSQL?

Fill the port value as 5432 that runs the Docker PostgreSQL Container and provide the name of the database as postgres. Then, fill the username and password fields with the credentials you created while running the PGAdmin container. After providing all required details, click on the “Save” button.

Does Docker use Tmpfs?

If you're running Docker on Linux, you have a third option: tmpfs mounts. When you create a container with a tmpfs mount, the container can create files outside the container's writable layer. As opposed to volumes and bind mounts, a tmpfs mount is temporary, and only persisted in the host memory.

What port does Postgres Docker use?

Docker automatically maps the default PostgreSQL server port 5432 in the container to a host port within the ephemeral port range (typically from 32768 to 61000).

What is tmpfs mounts in Docker?

If you’re running Docker on Linux, you have a third option: tmpfs mounts. When you create a container with a tmpfs mount, the container can create files outside the container’s writable layer.

Is there a docker image for PostgreSQL?

Assuming there is no Docker image that suits your needs on the Docker Hub, you can create one yourself. Note : This PostgreSQL setup is for development-only purposes.

How do I run some-Postgres in Docker?

$ docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres The default postgres user and database are created in the entrypoint with initdb. The postgres database is a default database meant for use by users, utilities and third party applications.

What version of PostgreSQL do I need to run a container?

We will be using the latest version 14.1 of PostgreSQL. The default bullseye version of Postgres docker image is 130 MB whereas the alpine one for the same version is 78 MB which is a lot smaller. To simply run the container using the Postgres 14.1 alpine image we can execute the following command:


1 Answers

My questions is: why did the speed of the tests did not change? And what can I do about it ?

If the table is so small that it already fits into ram, tmpfs doesn't gain you much except a few flushes to the disk. And, if that disk is an SSD it's not much at all. Typically you can make your testing suite go faster by turning off the Durability Options.

like image 119
NO WAR WITH RUSSIA Avatar answered Oct 16 '22 23:10

NO WAR WITH RUSSIA