限制本地开发环境 Elasticsearch 内存使用的最佳实践

Best practices on limiting memory usage of Elasticsearch for local development environment

我在 Rails 应用程序上有一个 Ruby,我使用 Docker Compose 在本地开发。我总是使用我们的生产 PostgreSQL 数据库的副本,该数据库非常大,大约有 500,000 行。使用 Searchkick gem 可以为 Elasticsearch 中的搜索索引很多数据。我想尽可能地重现生产环境,但我的笔记本电脑上 Elasticsearch 的大量 RAM 使用率降低了我的速度。我经常使用超过 10GB 的 RAM。

有没有人想过限制 Elasticsearch RAM 使用的解决方案,只用于本地开发?

这是我的 docker-compose.yml 文件中的 Elasticsearch 设置:

  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.11.1
    environment:
      - "discovery.type=single-node"
      - "ELASTIC_USERNAME=elastic"
      - "ELASTIC_PASSWORD=DkIedPPSCb"
      - "xpack.security.enabled=true"
    ports: ['9200:9200', '9300:9300']

与 elasticsearch 相比,这更像是一个 docker 配置。 如果您使用的是 docker-compose 的 v2,请在 docker compose

中设置以下标志

参考:Mem and CPU V2

  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.11.1
    environment:
      - "discovery.type=single-node"
      - "ELASTIC_USERNAME=elastic"
      - "ELASTIC_PASSWORD=DkIedPPSCb"
      - "xpack.security.enabled=true"
    ports: ['9200:9200', '9300:9300']
    mem_limit: 1024m

如果是 v3,像这样设置内存配置:

参考:Mem and CPU V3

  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.11.1
    environment:
      - "discovery.type=single-node"
      - "ELASTIC_USERNAME=elastic"
      - "ELASTIC_PASSWORD=DkIedPPSCb"
      - "xpack.security.enabled=true"
    ports: ['9200:9200', '9300:9300']
    deploy:
      resources:
        limits:
          cpus: '0.50'
          memory: 50M
        reservations:
          cpus: '0.25'
          memory: 20M