hasura graphql-engine集成pgbouncer 连接池工具

pgbouncer 是一个轻量的pg 连接池工具,我们可以和hasura graphql-engine集成起来,进行连接的一些优化

环境准备

  • docker-compose 文件
version: '3.6'
services:
  postgres:
    image: postgres:9.6
    ports:
    - "5432:5432"
    environment:
    - "POSTGRES_PASSWORD:dalong"
    volumes:
    - ./db_data2:/var/lib/postgresql/data
  pgbouncer:
    image: brainsam/pgbouncer
    environment:
    - DB_HOST=postgres
    - DB_USER=postgres
    - DB_PASSWORD=dalong
    ports:
    - "6432:6432"
  graphql-engine:
    image: hasura/graphql-engine:v1.0.0-alpha30
    ports:
    - "8080:8080"
    depends_on:
    - "postgres"
    environment:
    - "POSTGRES_PASSWORD:dalong"
    command: >
      /bin/sh -c "
      graphql-engine --database-url postgres://postgres:dalong@pgbouncer:6432/postgres serve --enable-console;
      "

说明

方式一样,主要是修改了连接的地址,因为使用了pgbouncer,地址修改为了pgbouncer server的地址,同时
对于pgbouncer server 配置了后端的pg server, 实际上hasura graphql-engine,后端的连接自身是支持数据库
连接池的,性能也很不错,但是如果使用引擎进行应用开发,参考3factor 的模型,是会存在数据回写的,使用
连接池工具可以帮助我们做好多事情,比如ha的处理,可以做到一些性能的提升

参考资料

https://github.com/pgbouncer/pgbouncer
https://hub.docker.com/r/brainsam/pgbouncer/
https://www.percona.com/blog/2018/06/27/scaling-postgresql-with-pgbouncer-you-may-need-a-connection-pooler-sooner-than-you-expect/

posted on 2018-11-30 20:46  荣锋亮  阅读(569)  评论(0编辑  收藏  举报

导航