1

I am using a Laravel application with MySql using docker image mysql:8.0.

When I use the Laravel db:seed command,then mysql container will only manage to insert max 200 rows per minute (each row has just 3 columns, id, name , date).

enter image description here

I am using Ubuntu 18.04 with the following hardware:

enter image description here

Is there any chance that I can configure my MySql settings, so that the docker image will be able to handle more writes per second? Maybe 10,000 per second?

Here is my docker-compose.yml file:

version: '3'
services:
    laravel.test:
        build:
            context: ./docker/8.0
            dockerfile: Dockerfile
            args:
                WWWGROUP: '${WWWGROUP}'
        image: sail-8.0/app
        extra_hosts:
            - 'host.docker.internal:host-gateway'
        ports:
            - '${APP_PORT:-80}:80'
        environment:
            WWWUSER: '${WWWUSER}'
            LARAVEL_SAIL: 1
            XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
            XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
        volumes:
            - '.:/var/www/html'
        networks:
            - sail
        depends_on:
            - mysql
            - redis
            - meilisearch
            - selenium
    mysql:
        image: 'mysql:8.0'
        ports:
            - '${FORWARD_DB_PORT:-3306}:3306'
        environment:
            MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
            MYSQL_DATABASE: '${DB_DATABASE}'
            MYSQL_USER: '${DB_USERNAME}'
            MYSQL_PASSWORD: '${DB_PASSWORD}'
            MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
        volumes:
            - 'sailmysql:/var/lib/mysql'
            - './docker/8.0/my.cnf:/etc/mysql/my.cnf'    
        networks:
            - sail
        healthcheck:
            test: ["CMD", "mysqladmin", "ping", "-p${DB_PASSWORD}"]
            retries: 3
            timeout: 5s

These are my my.cnf settings:

innodb_io_capacity = 2000
innodb_read_io_threads = 64
innodb_thread_concurrency = 64
innodb_write_io_threads = 64
Adam
  • 25,960
  • 22
  • 158
  • 247
  • run the server in a dedicated server and not in a docker. but thsi could also be a problem with the queries as the server shows a high level. The usual is to enable sklwo query log and see if there are some heavy queries that need optimation – nbk Nov 06 '21 at 12:31
  • @nbk I am doing local development. All this seed is doing is 10000 times `INSERT INTO companies ('name') VALUES ('Microsoft')` (with different names) I may improve this with chunks, but its just feels so slow, that I think I have some configuration issue,. – Adam Nov 06 '21 at 12:35
  • bulk inserts are always tricky, so mysql has some hints for it have you checked them? – nbk Nov 06 '21 at 12:42
  • @nbk, yes, I can use bulks to increase the performance by a lot. But despite that, I am wondering why my machine only allows up to 200writes per second. Forexample this author https://laravelproject.com/how-to-seed-records-in-laravel-quickly/ states that he can insert 10k rows in 8s, which means he can do 12,500 writes per second! – Adam Nov 06 '21 at 14:24
  • If you using mysql only for tests - check here: https://medium.com/@2618094/speed-up-feature-tests-in-laravel-with-docker-compose-and-tmpfs-a845a278d072 – Maksim Nov 06 '21 at 15:54

0 Answers0