From 876f9bb07fa78f05dd79e4d35d6a48ef15b3976a Mon Sep 17 00:00:00 2001 From: Timothy Messier Date: Mon, 5 Jun 2023 16:37:42 +0000 Subject: [PATCH 1/2] fix(session): List performance with large number of session connections As part of the performance improvements for listing sessions for v0.9.0, the view used to retrieve sessions for listing was updated to no longer include a join on session_connection. However, a later migration that was adding additional columns to this view inadvertently re-added the join and session_connection columns. This resulted in requests to list sessions performing this join, and returning additional rows for each connection in a session. The application would ignore this additional data, since it is no longer returned via the API. This would be particularly impactful in cases where there are a large number of connections per session, as this would greatly increase the amount of data returned by the database. This fix removes the session_connection join from this view, which should restore the original performance improvements even in cases where there is a large number of session connections per session. See: https://github.com/hashicorp/boundary/pull/2160 Ref: 32070678dc712812a42a511bb68f668658bd327a Fixes: 1e3c941be11086e4fa3cbba3e90cb160377103b3 --- CHANGELOG.md | 3 ++ .../69/02_session_worker_protocol.up.sql | 1 + .../72/03_session_list_perf_fix.up.sql | 40 +++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 internal/db/schema/migrations/oss/postgres/72/03_session_list_perf_fix.up.sql diff --git a/CHANGELOG.md b/CHANGELOG.md index a26f9db58..1f129b377 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -66,6 +66,9 @@ Canonical reference for changes, improvements, and bugfixes for Boundary. * resource listing: API requests to list a resource (targets, sessions, users, etc) now properly return all resources the callers has appropriate permission to list ([PR](https://github.com/hashicorp/boundary/pull/3278)) +* sessions: Fix a bug that contributed to slow response times when listing + sessions that had a large number of connections + ([PR](https://github.com/hashicorp/boundary/pull/3280)) ## 0.12.3 (2023/05/26) diff --git a/internal/db/schema/migrations/oss/postgres/69/02_session_worker_protocol.up.sql b/internal/db/schema/migrations/oss/postgres/69/02_session_worker_protocol.up.sql index 2b0100f7d..53ab2d2e1 100644 --- a/internal/db/schema/migrations/oss/postgres/69/02_session_worker_protocol.up.sql +++ b/internal/db/schema/migrations/oss/postgres/69/02_session_worker_protocol.up.sql @@ -18,6 +18,7 @@ begin; drop view session_list; -- Replaces view from 60/02_sessions.up.sql to add swp.worker_id + -- Replaced in 72/03_session_list_perf_fix.up.sql create view session_list as select s.public_id, diff --git a/internal/db/schema/migrations/oss/postgres/72/03_session_list_perf_fix.up.sql b/internal/db/schema/migrations/oss/postgres/72/03_session_list_perf_fix.up.sql new file mode 100644 index 000000000..e41a8c658 --- /dev/null +++ b/internal/db/schema/migrations/oss/postgres/72/03_session_list_perf_fix.up.sql @@ -0,0 +1,40 @@ +-- Copyright (c) HashiCorp, Inc. +-- SPDX-License-Identifier: MPL-2.0 + +begin; + + -- Replaces the view created in 69/02_session_worker_protocol.up.sql + drop view session_list; + create view session_list as + select s.public_id, + s.user_id, + shsh.host_id, + s.target_id, + shsh.host_set_id, + s.auth_token_id, + s.project_id, + s.certificate, + s.certificate_private_key, + s.expiration_time, + s.connection_limit, + s.tofu_token, + s.key_id, + s.termination_reason, + s.version, + s.create_time, + s.update_time, + s.endpoint, + s.worker_filter, + s.egress_worker_filter, + s.ingress_worker_filter, + swp.worker_id, + ss.state, + ss.previous_end_time, + ss.start_time, + ss.end_time + from session s + join session_state ss on s.public_id = ss.session_id + left join session_host_set_host shsh on s.public_id = shsh.session_id + left join session_worker_protocol swp on s.public_id = swp.session_id; + +commit; From 603642f27151057393b1e73de7c5a401848695e4 Mon Sep 17 00:00:00 2001 From: Timothy Messier Date: Tue, 6 Jun 2023 13:10:11 -0400 Subject: [PATCH 2/2] fix(session): List performance with large number of session connections (#3288) As part of the performance improvements for listing sessions for v0.9.0, the view used to retrieve sessions for listing was updated to no longer include a join on session_connection. However, a later migration that was adding additional columns to this view inadvertently re-added the join and session_connection columns. This resulted in requests to list sessions performing this join, and returning additional rows for each connection in a session. The application would ignore this additional data, since it is no longer returned via the API. This would be particularly impactful in cases where there are a large number of connections per session, as this would greatly increase the amount of data returned by the database. This fix removes the session_connection join from this view, which should restore the original performance improvements even in cases where there is a large number of session connections per session. See: https://github.com/hashicorp/boundary/pull/2160 Ref: 32070678dc712812a42a511bb68f668658bd327a Fixes: 1e3c941be11086e4fa3cbba3e90cb160377103b3 (cherry picked from commit 7aef341682e65b42c1b919e03936bdf81e26e87c) --- .../oss/postgres/60/02_sessions.up.sql | 2 +- .../oss/postgres/64/04_session_list.up.sql | 38 +++++++++++++++++++ .../69/02_session_worker_protocol.up.sql | 2 +- 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 internal/db/schema/migrations/oss/postgres/64/04_session_list.up.sql diff --git a/internal/db/schema/migrations/oss/postgres/60/02_sessions.up.sql b/internal/db/schema/migrations/oss/postgres/60/02_sessions.up.sql index 3d83ecf6c..344e92754 100644 --- a/internal/db/schema/migrations/oss/postgres/60/02_sessions.up.sql +++ b/internal/db/schema/migrations/oss/postgres/60/02_sessions.up.sql @@ -176,7 +176,7 @@ begin; for each row execute procedure insert_session(); -- Replaces view from 59/01_target_ingress_egress_worker_filters.up.sql - -- Replaced in 69/02_session_worker_protocol.up.sql + -- Replaced in 64/04_session_list.up.sql create view session_list as select s.public_id, diff --git a/internal/db/schema/migrations/oss/postgres/64/04_session_list.up.sql b/internal/db/schema/migrations/oss/postgres/64/04_session_list.up.sql new file mode 100644 index 000000000..720e5ecf1 --- /dev/null +++ b/internal/db/schema/migrations/oss/postgres/64/04_session_list.up.sql @@ -0,0 +1,38 @@ +-- Copyright (c) HashiCorp, Inc. +-- SPDX-License-Identifier: MPL-2.0 + +begin; + + -- Replaces view from 60/02.02_sessions.up.sql + drop view session_list; + create view session_list as + select s.public_id, + s.user_id, + shsh.host_id, + s.target_id, + shsh.host_set_id, + s.auth_token_id, + s.project_id, + s.certificate, + s.certificate_private_key, + s.expiration_time, + s.connection_limit, + s.tofu_token, + s.key_id, + s.termination_reason, + s.version, + s.create_time, + s.update_time, + s.endpoint, + s.worker_filter, + s.egress_worker_filter, + s.ingress_worker_filter, + ss.state, + ss.previous_end_time, + ss.start_time, + ss.end_time + from session s + join session_state ss on s.public_id = ss.session_id + left join session_host_set_host shsh on s.public_id = shsh.session_id; + +commit; diff --git a/internal/db/schema/migrations/oss/postgres/69/02_session_worker_protocol.up.sql b/internal/db/schema/migrations/oss/postgres/69/02_session_worker_protocol.up.sql index 53ab2d2e1..015058fe1 100644 --- a/internal/db/schema/migrations/oss/postgres/69/02_session_worker_protocol.up.sql +++ b/internal/db/schema/migrations/oss/postgres/69/02_session_worker_protocol.up.sql @@ -17,7 +17,7 @@ begin; ); drop view session_list; - -- Replaces view from 60/02_sessions.up.sql to add swp.worker_id + -- Replaces view from 64/04_session_list.up.sql to add swp.worker_id -- Replaced in 72/03_session_list_perf_fix.up.sql create view session_list as select