减少python测试阶段的管道执行时间

问题描述

感谢您的支持,因为我需要减少运行 python 测试用例的管道执行时间

通过我的本地机器需要 3 分钟或更短时间,但通过管道机器需要 8 分钟或更长时间

本地机器

处理器 Intel(R) Core(TM) i7-4510U cpu @ 2.00GHz

内存 16GiB 系统内存

Cloudbuild 流水线机器

8 个 vcpu 8 Gib RAM

我使用以下命令来执行测试用例,但没有什么不同 所以我认为测试人员不能并行工作,8个cpu内核没有很好地使用 或者 docker-compose 步骤没有使用流水线机器的全部功能

pytest -n 4
pytest -n 6 
pytest -n auto 

我的 docker-compose 文件

version: '3'
services:
  redis:
    image: registry.hub.docker.com/library/redis:latest
    expose:
        - 6379
  postgres:
    image: registry.hub.docker.com/library/postgres:9.6
    restart: always
    command: -c max_connections=3000 -c fsync=off -c synchronous_commit=off -c full_page_writes=off -c max_locks_per_transaction=500
    volumes:
        - ./postgres/pgdata:/var/lib/postgresql/data
    environment:
        - POSTGRES_PASSWORD=my-postgres-pass
        - POSTGRES_USER=my-postgres-user
        - POSTGRES_DB=my-postgres-db
    expose:
        - "5432"
  datastore:
    image: registry.hub.docker.com/google/cloud-sdk
    entrypoint: bash
    command: gcloud beta emulators datastore start --host-port 0.0.0.0:8081
    environment:
        - CLOUDSDK_CORE_PROJECT=my-project
    expose:
        - "8081"
  pubsub:
    image: registry.hub.docker.com/google/cloud-sdk
    entrypoint: bash
    command: gcloud beta emulators pubsub start --host-port 0.0.0.0:8085
    environment:
        - CLOUDSDK_CORE_PROJECT=my-project
    expose:
        - "8085"
  django:
    working_dir: /opt/my-project
    image: $GUNICORN_IMAGE_NAME
    entrypoint: bash
    command: >
        -c "
        /usr/local/bin/pip install -r /opt/my-project/requirements.dev.txt &&
        python manage.py migrate_schemas &&
        pytest -n auto ."
    depends_on:
        - postgres
        - redis
        - datastore
        - pubsub
    environment:
        ......

我的云构建文件

- name: "gcr.io/cloud-builders/docker"
  id: 'gunicorn_build'
  args: ['build','-t','gcr.io/${PROJECT_ID}/${REPO_NAME}-gunicorn:${BRANCH_NAME}-${SHORT_SHA}','.']


- name: 'gcr.io/$PROJECT_ID/docker-compose'
  id: 'test_cases'
  args: ['-f','./docker/docker-compose.yml','up','--abort-on-container-exit','--exit-code-from','django' ]
  env:
  - 'GUNICORN_IMAGE_NAME=gcr.io/${PROJECT_ID}/${REPO_NAME}-gunicorn:${BRANCH_NAME}-${SHORT_SHA}'


options:
  machineType: 'E2_HIGHcpu_8'

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)