Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

running postgrest-loadtest with artificial latency #2682

Merged
merged 2 commits into from
Mar 20, 2023
Merged

Conversation

robx
Copy link
Contributor

@robx robx commented Feb 24, 2023

This pipes traffic between the client and postgrest and between postgrest and postgresql through a helper tool (https://github.com/robx/slocat) that adds a configurable amount of latency. I'm not suggesting this be merged, just filing it here for discussion at #2295.

This can be used like

$ PGDELAY=1ms PGRST_DELAY=10ms postgrest-loadtest
delaying data to/from postgres by 1ms
Building postgrest... done.
Starting postgrest... done.
delaying data to/from PostgREST by 10ms
...

@robx robx mentioned this pull request Feb 24, 2023
@robx robx changed the title running postgrest-loadtest with artifical latency running postgrest-loadtest with artificial latency Mar 16, 2023
Copy link
Member

@steve-chavez steve-chavez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@robx I think this one is good to merge. It's self-contained in a Nix command and seems useful on its own.

It will also make #2707 shorter.

@robx
Copy link
Contributor Author

robx commented Mar 20, 2023

@robx I think this one is good to merge. It's self-contained in a Nix command and seems useful on its own.

It will also make #2707 shorter.

Hmm ok if you say so :). Then I'll polish it up a bit and merge.

robx added 2 commits March 20, 2023 13:59
This pipes data between client/postgrest and between
postgrest/database through a proxy that adds delay
(github.com/robx/slocat).
By default, postgrest-with-pgrst builds postgrest as a nix package,
which means that source changes cause a full rebuild. With this
change, running the loadtest as

PGRST_BUILD_CABAL=1 postgrest-loadtest

rebuilds directly using cabal, like postgrest-build. Note that
results between nix and cabal builds aren't necessarily comparable
due to differing build parameters.
@robx
Copy link
Contributor Author

robx commented Mar 20, 2023

I also pulled in the build-with-cabal option here.

@robx robx marked this pull request as ready for review March 20, 2023 13:38
@robx robx merged commit e731241 into PostgREST:main Mar 20, 2023
@robx robx deleted the with-slow branch March 20, 2023 14:00
Comment on lines +353 to 354
$PGRST_CMD ${legacyConfig} > "$tmpdir"/run.log 2>&1 &
pid=$!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before the change to nix-build we had some more magic here to get the correct pid for cleanup, see your first commit around this area: 0c5d2e5

Aren't we back to getting the cabal pid, or even worse the bash pid from postgrest-run, which will prevent stopping postgrest properly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When PGRST_BUILD_CABAL isn't set, nothing changes. Otherwise, it's cabal's job to deal with its children, which it should do properly in recent releases (not entirely sure whether nixpkgs has caught up there).

Comment on lines +337 to +349
if [ -z "''${PGRST_BUILD_CABAL:-}" ]; then
echo -n "Building postgrest (nix)... "
nix-build -A postgrestPackage > "$tmpdir"/build.log 2>&1 || {
echo "failed, output:"
cat "$tmpdir"/build.log
exit 1
}
PGRST_CMD=./result/bin/postgrest
else
echo -n "Building postgrest (cabal)... "
postgrest-build
PGRST_CMD=postgrest-run
fi
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is PGRST_BUILD_CABAL really the right term? nix-build does nothing different - it builds with cabal, too.

The difference seems to be in:

  • Which dependencies are used, so in which nix environment is the command run? This branch or main?
  • Is cabal's build cache re-used? The nix command probably does not, but postgrest-build does, right?

I think PGRST_BUILD_CABAL is misleading. It's actually going back to using the current nix environment, so the dependency problem would still be present with that setting, correct?

Overall, I think the fix in 0c5d2e5 was just not an improvement and we should revert it.

The suggestion I made in #2308 (comment) seems better. The loadtest-against / with-git infrastructure was designed to always use the current's branch nix environment on purpose. This does not cover some edge-cases, like the one you found - but it gives us some nice other properties, namely that we can update our tooling (nix commands for loadtest etc..) - and still run the new tools on older branches. This was necessary when I once ran loadtest through some months/years of commits to see patterns: #1812 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't particularly care what happens to this change as such -- I needed it to do my work here.

(It's unfortunate that our nix tooling is as rigid and obstructive as it is, it would be much preferable if changes such as this weren't needed. Ideally, it were possible to iterate quickly with local changes to the build scripts, but that's not where we're at.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants