From 97cd559265a22603b029893533524d8e44618f9a Mon Sep 17 00:00:00 2001 From: steve-chavez Date: Wed, 28 Feb 2024 13:28:20 -0500 Subject: [PATCH 1/3] nix: add postgrest-profiled-run Runs a profiled build of postgREST that can be used for optimization. --- default.nix | 2 +- nix/tools/memory.nix | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/default.nix b/default.nix index 48903f3fc0..32f9f992ba 100644 --- a/default.nix +++ b/default.nix @@ -134,7 +134,7 @@ rec { # Script for running memory tests. memory = - pkgs.callPackage nix/tools/memory.nix { inherit postgrestProfiled withTools; }; + pkgs.callPackage nix/tools/memory.nix { inherit postgrestProfiled postgrest withTools; }; # Utility for updating the pinned version of Nixpkgs. nixpkgsTools = diff --git a/nix/tools/memory.nix b/nix/tools/memory.nix index 15683275d3..1c00d04817 100644 --- a/nix/tools/memory.nix +++ b/nix/tools/memory.nix @@ -5,6 +5,7 @@ , checkedShellScript , curl , postgrestProfiled +, postgrest , withTools }: let @@ -20,9 +21,32 @@ let ${withTools.withPg} -f test/spec/fixtures/load.sql test/memory/memory-tests.sh ''; + runProfiled = + checkedShellScript + { + name = "postgrest-profiled-run"; + docs = "Run a profiled build of postgREST. This will generate a postgrest.prof file that can be used to do optimization."; + args = + [ + "ARG_USE_ENV([PGRST_DB_ANON_ROLE], [postgrest_test_anonymous], [PostgREST anonymous role])" + "ARG_USE_ENV([PGRST_DB_POOL], [1], [PostgREST pool size])" + "ARG_USE_ENV([PGRST_DB_POOL_ACQUISITION_TIMEOUT], [1], [PostgREST pool size])" + "ARG_LEFTOVERS([PostgREST arguments])" + ]; + workingDir = "/"; + withPath = [ postgrestProfiled ]; + withEnv = postgrest.env; + } + '' + export PGRST_DB_ANON_ROLE + export PGRST_DB_POOL + export PGRST_DB_POOL_ACQUISITION_TIMEOUT + + postgrest +RTS -p -h -RTS "''${_arg_leftovers[@]}" + ''; in buildToolbox { name = "postgrest-memory"; - tools = { inherit test; }; + tools = { inherit test runProfiled; }; } From a6b7db4f2f64c28f1a86828ac41771bcebc3f15e Mon Sep 17 00:00:00 2001 From: steve-chavez Date: Wed, 28 Feb 2024 15:09:18 -0500 Subject: [PATCH 2/3] feedback --- default.nix | 2 +- nix/tools/cabalTools.nix | 2 +- nix/tools/memory.nix | 4 +--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/default.nix b/default.nix index 32f9f992ba..48903f3fc0 100644 --- a/default.nix +++ b/default.nix @@ -134,7 +134,7 @@ rec { # Script for running memory tests. memory = - pkgs.callPackage nix/tools/memory.nix { inherit postgrestProfiled postgrest withTools; }; + pkgs.callPackage nix/tools/memory.nix { inherit postgrestProfiled withTools; }; # Utility for updating the pinned version of Nixpkgs. nixpkgsTools = diff --git a/nix/tools/cabalTools.nix b/nix/tools/cabalTools.nix index decef9ab17..0174d7fa3c 100644 --- a/nix/tools/cabalTools.nix +++ b/nix/tools/cabalTools.nix @@ -42,7 +42,7 @@ let [ "ARG_USE_ENV([PGRST_DB_ANON_ROLE], [postgrest_test_anonymous], [PostgREST anonymous role])" "ARG_USE_ENV([PGRST_DB_POOL], [1], [PostgREST pool size])" - "ARG_USE_ENV([PGRST_DB_POOL_ACQUISITION_TIMEOUT], [1], [PostgREST pool size])" + "ARG_USE_ENV([PGRST_DB_POOL_ACQUISITION_TIMEOUT], [1], [PostgREST pool timeout])" "ARG_LEFTOVERS([PostgREST arguments])" ]; workingDir = "/"; diff --git a/nix/tools/memory.nix b/nix/tools/memory.nix index 1c00d04817..0c7f731c94 100644 --- a/nix/tools/memory.nix +++ b/nix/tools/memory.nix @@ -5,7 +5,6 @@ , checkedShellScript , curl , postgrestProfiled -, postgrest , withTools }: let @@ -30,12 +29,11 @@ let [ "ARG_USE_ENV([PGRST_DB_ANON_ROLE], [postgrest_test_anonymous], [PostgREST anonymous role])" "ARG_USE_ENV([PGRST_DB_POOL], [1], [PostgREST pool size])" - "ARG_USE_ENV([PGRST_DB_POOL_ACQUISITION_TIMEOUT], [1], [PostgREST pool size])" + "ARG_USE_ENV([PGRST_DB_POOL_ACQUISITION_TIMEOUT], [1], [PostgREST pool timeout])" "ARG_LEFTOVERS([PostgREST arguments])" ]; workingDir = "/"; withPath = [ postgrestProfiled ]; - withEnv = postgrest.env; } '' export PGRST_DB_ANON_ROLE From ed222936f0b3e781645f9fe48520fd5265fb58f4 Mon Sep 17 00:00:00 2001 From: steve-chavez Date: Thu, 29 Feb 2024 11:54:15 -0500 Subject: [PATCH 3/3] add note about not being reactive --- nix/tools/memory.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nix/tools/memory.nix b/nix/tools/memory.nix index 0c7f731c94..a39178afe2 100644 --- a/nix/tools/memory.nix +++ b/nix/tools/memory.nix @@ -1,6 +1,7 @@ # The memory tests have large dependencies (a profiled build of PostgREST) # and are run less often than the spec tests, so we don't include them in # the default test environment. We make them available through a separate module. +# TODO both of these require reentering the nix-shell if you make a change to the code { buildToolbox , checkedShellScript , curl @@ -24,7 +25,7 @@ let checkedShellScript { name = "postgrest-profiled-run"; - docs = "Run a profiled build of postgREST. This will generate a postgrest.prof file that can be used to do optimization."; + docs = "Run a profiled build of postgREST. This will generate a postgrest.prof file that can be used to do optimization. Note: if you make a change to the code, you must reenter the nix-shell for an updated profiled build."; args = [ "ARG_USE_ENV([PGRST_DB_ANON_ROLE], [postgrest_test_anonymous], [PostgREST anonymous role])"