From 54f67697b400198b7c05bba880e7e019684a108e Mon Sep 17 00:00:00 2001
From: Dan Notestein <dan@syncad.com>
Date: Thu, 5 Dec 2024 03:56:24 +0000
Subject: [PATCH] add option to run legcy python server for now, and increase
 postgrest connection pool (seems to help loading)

---
 exposed/hivemind.exposed.yaml |  8 ++++++++
 haf_base.yaml                 |  1 +
 hivemind.yaml                 | 24 ++++++++++++++++++++----
 pgtune.conf                   |  2 +-
 postgrest/Dockerfile          |  2 +-
 5 files changed, 31 insertions(+), 6 deletions(-)

diff --git a/exposed/hivemind.exposed.yaml b/exposed/hivemind.exposed.yaml
index 9ad23db..51657c3 100644
--- a/exposed/hivemind.exposed.yaml
+++ b/exposed/hivemind.exposed.yaml
@@ -1,4 +1,12 @@
 services:
+  # When we want to benchmark the old hivemind server against the new, you can use this
+  # to expose it on a different port from the postgrest version.  For everyone else,
+  # it's not needed at all.  This should be removed once we remove the config for the 
+  # python version of the server.
+  #
+  # hivemind-server:
+  #   ports:
+  #     - "${HAF_API_NODE_EXPOSED_IPADDR:-0.0.0.0}:${HAF_API_NODE_EXPOSED_PORT_PREFIX:-3}7002:8080"
   hivemind-postgrest-rewriter:
     ports:
       - "${HAF_API_NODE_EXPOSED_IPADDR:-0.0.0.0}:${HAF_API_NODE_EXPOSED_PORT_PREFIX:-1}7002:80"
diff --git a/haf_base.yaml b/haf_base.yaml
index e203b57..2f9d54f 100644
--- a/haf_base.yaml
+++ b/haf_base.yaml
@@ -56,6 +56,7 @@ services:
         host    haf_block_log    hivemind         ${COMPOSE_PROJECT_NAME}-hivemind-install-1.${NETWORK_NAME}                    trust\n
         host    haf_block_log    haf_admin        ${COMPOSE_PROJECT_NAME}-hivemind-block-processing-1.${NETWORK_NAME}           trust\n
         host    haf_block_log    hivemind         ${COMPOSE_PROJECT_NAME}-hivemind-block-processing-1.${NETWORK_NAME}           trust\n
+        host    haf_block_log    haf_admin        ${COMPOSE_PROJECT_NAME}-hivemind-server-1.${NETWORK_NAME}                     trust\n
         host    haf_block_log    hivemind         ${COMPOSE_PROJECT_NAME}-hivemind-server-1.${NETWORK_NAME}                     trust\n
         host    haf_block_log    hivemind         ${COMPOSE_PROJECT_NAME}-hivemind-postgrest-server-1.${NETWORK_NAME}           trust\n
 
diff --git a/hivemind.yaml b/hivemind.yaml
index dc1dc87..1c4f0ab 100644
--- a/hivemind.yaml
+++ b/hivemind.yaml
@@ -23,6 +23,22 @@ services:
       reputation-tracker-install:
         condition: service_completed_successfully
 
+  hivemind-server:
+    image: ${HIVEMIND_IMAGE:-${HIVE_API_NODE_REGISTRY:-registry.hive.blog}/hivemind}:${HIVEMIND_VERSION:-${HIVE_API_NODE_VERSION}}
+    profiles:
+      - apps
+      - hivemind
+    networks:
+      haf-network:
+    command:
+      - "--database-url=postgresql://hivemind@haf/haf_block_log"
+      - "server"
+    depends_on:
+      hivemind-block-processing:
+        condition: service_healthy
+      haf:
+        condition: service_healthy
+
   hivemind-postgrest-server:
     image: ${POSTGREST_IMAGE:-registry.gitlab.syncad.com/hive/haf_api_node/postgrest}:${POSTGREST_VERSION:-latest}
     profiles:
@@ -33,15 +49,15 @@ services:
     environment:
       PGRST_ADMIN_SERVER_PORT: 3001
       PGRST_SERVER_PORT: 8080
-      PGRST_DB_URI: "postgresql://hivemind@haf/haf_block_log?application_name=hive-mind-postgrest" #warning hivemind improperly matches all connections starting from `hivemind` and crashes if they are made externally (not from python)
+      PGRST_DB_URI: "postgresql://hivemind@haf/haf_block_log?application_name=hive-mind-postgrest" # warning hivemind improperly matches all connections starting from `hivemind` and crashes if they are made externally (not from python)
       PGRST_DB_SCHEMA: hivemind_endpoints
-      #PGRST_DB_ROOT_SPEC: home
+      # PGRST_DB_ROOT_SPEC: home
       PGRST_DB_ANON_ROLE: hivemind
-      PGRST_DB_POOL: 20
+      PGRST_DB_POOL: 40
       PGRST_DB_POOL_ACQUISITION_TIMEOUT: 10
       PGRST_OPENAPI_MODE: "disabled" # unclear why this is set, I guess because we currently only support json-rpc?
       # when debugging, you can enable this
-      PGRST_DB_PLAN_ENABLED: true
+      # PGRST_DB_PLAN_ENABLED: true
     healthcheck:
       test: ["CMD-SHELL", "wget --timeout=2 -nv -t1 --spider 127.0.0.1:3001/ready || exit 1"]
       interval: 10s
diff --git a/pgtune.conf b/pgtune.conf
index aec54b7..b80b4fc 100644
--- a/pgtune.conf
+++ b/pgtune.conf
@@ -1,5 +1,5 @@
 shared_buffers = 16GB
-effective_cache_size = 8GB
+effective_cache_size = 48GB
 maintenance_work_mem = 4GB
 work_mem = 1024MB
 
diff --git a/postgrest/Dockerfile b/postgrest/Dockerfile
index c74b1a7..0b2f087 100644
--- a/postgrest/Dockerfile
+++ b/postgrest/Dockerfile
@@ -1,4 +1,4 @@
-ARG POSTGREST_VERSION=v12.0.2
+ARG POSTGREST_VERSION=v12.2.3
 FROM postgrest/postgrest:${POSTGREST_VERSION} AS postgrest-base
 FROM alpine:latest AS base
 COPY --from=postgrest-base /bin/postgrest /bin
-- 
GitLab