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

Epic: Latency #3548

Closed
2 tasks
Tracked by #1755
vadim2404 opened this issue Feb 6, 2023 · 2 comments
Closed
2 tasks
Tracked by #1755

Epic: Latency #3548

vadim2404 opened this issue Feb 6, 2023 · 2 comments
Assignees
Labels
c/cloud/proxy Component: cloud: proxy t/Epic Issue type: Epic

Comments

@vadim2404
Copy link
Contributor

vadim2404 commented Feb 6, 2023

Motivation

To reduce latency between end-user and the proxy

DoD

TODO

Discussion

Tasks

@vadim2404 vadim2404 added c/cloud/proxy Component: cloud: proxy t/Epic Issue type: Epic labels Feb 6, 2023
@hlinnaka
Copy link
Contributor

hlinnaka commented Feb 6, 2023

#3458 can be quite helpful in investigating this

@funbringer funbringer mentioned this issue Feb 6, 2023
19 tasks
@kelvich
Copy link
Contributor

kelvich commented Feb 7, 2023

I've tried to set up local test without any Cloudflare/Vercel things using browser.

Build proxy:

> cd ~/code/neon
> cargo build --release

Generate self-signed certs:

> openssl req -new -x509 -days 365 -nodes -text -out server.crt -keyout server.key -subj "/CN=*.localtest.me"

Start proxy with --auth-backend=postgres (redirect connection to the local postgres instances, auth info queried from the same postgres):

> ./target/debug/proxy -c server.crt -k server.key --wss '127.0.0.1:7500' --auth-backend=postgres --auth-endpoint 'postgres://stas:stas@localhost/postgres'
2023-02-07T15:15:05.073890Z  INFO Version: git:678fe0684fa28dd168f56cf7b0ea71ab71efc580
2023-02-07T15:15:05.076026Z  INFO Authentication backend: Postgres("postgres://stas:stas@localhost/postgres")
2023-02-07T15:15:05.076057Z  INFO Starting http on 127.0.0.1:7001
2023-02-07T15:15:05.076161Z  INFO Starting mgmt on 127.0.0.1:7000
2023-02-07T15:15:05.076198Z  INFO Starting proxy on 127.0.0.1:4432
2023-02-07T15:15:05.076293Z  INFO Starting wss on 127.0.0.1:7500

Now I've used the following js file:

import { Client, neonConfig } from '@neondatabase/serverless';

async function whatsTheTimeMrPostgres() {
  neonConfig.wsProxy = (host, _port) => host + ':7500/v2';
  neonConfig.pipelineConnect = true;
  neonConfig.pipelineTLS = true;
  neonConfig.coalesceWrites = true;

  const client = new Client('postgres://stas:stas@asdf.localtest.me:7500/postgres');
  await client.connect();
  const { rows: [{ now }] } = await client.query('select now();');
  await client.end();

  console.log('The postgres time is: ', now)
  return now;
}

(async () => {
  await whatsTheTimeMrPostgres();
})();

Bundled it with esbuild:

esbuild connect.js --bundle > res.js

And started in a browser by using the following html file:

<!DOCTYPE html><html><body>
<script src="res.js"></script>
</body></html>

Now browser gives the following:

The postgres time is:  
Date Tue Feb 07 2023 17:12:45 GMT+0200 (Eastern European Standard Time)

And proxy prints smth like:

2023-02-07T15:16:04.579880Z  INFO handshake: received StartupMessage { major_version: 3, minor_version: 0, params: StartupMessageParams { params: {"database": "postgres", "user": "stas", "client_encoding": "UTF8"} } }
2023-02-07T15:16:04.579911Z  INFO handshake: successful handshake session_type="normal"
2023-02-07T15:16:04.579935Z  INFO credentials user="stas" dbname="postgres" project="asdf" use_cleartext_password_flow=true
2023-02-07T15:16:04.579974Z  INFO registered new query cancellation key CancelKeyData(ffffffffda86ff04)
2023-02-07T15:16:04.580001Z  INFO auth: performing mock authentication using a local postgres instance
2023-02-07T15:16:04.580006Z  INFO auth: fetching user's authentication info
2023-02-07T15:16:04.587166Z  INFO auth:get_auth_info:postgres{url="postgres://stas:stas@localhost/postgres"}: got a secret: SCRAM-SHA-256$4096:AoNI28ojDliU3HY0KnVeKQ==$S0UkJ2HbD2pm9nJShge1NDE8NiD7J96MLnACPH2lNMs=:qeN8glwtEEq39mnKaT3X2JDOkr+YaChOTH+Zo3OuIU8=
2023-02-07T15:16:04.587221Z  INFO auth: auth endpoint chooses SCRAM
2023-02-07T15:16:04.880959Z  INFO auth: user successfully authenticated
2023-02-07T15:16:04.880999Z  INFO connect_to_compute:connect_once: trying to connect to a compute node at localhost:5432
2023-02-07T15:16:04.885393Z  INFO connect_to_compute:connect_once: connected to user's compute node at [::1]:5432
2023-02-07T15:16:04.885444Z  INFO prepare_client_connection: enabling query cancellation for this session
2023-02-07T15:16:04.885618Z  INFO proxy_pass: performing the proxy pass...
2023-02-07T15:16:04.894490Z  INFO dropped query cancellation key CancelKeyData(ffffffffda86ff04)

With or without pipelining I see ~300ms delay between auth endpoint chooses SCRAM and user successfully authenticated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c/cloud/proxy Component: cloud: proxy t/Epic Issue type: Epic
Projects
None yet
Development

No branches or pull requests

4 participants