The goal is to test a large scale Postgres instance and to make sure that we can successfully ingest data from it quickly.
(c: Composition, parser: WorkflowArgumentParser)
| 351 | |
| 352 | |
| 353 | def workflow_large_scale(c: Composition, parser: WorkflowArgumentParser) -> None: |
| 354 | """ |
| 355 | The goal is to test a large scale Postgres instance and to make sure that we can successfully ingest data from it quickly. |
| 356 | """ |
| 357 | pg_version = get_targeted_pg_version(parser) |
| 358 | with c.override( |
| 359 | create_postgres( |
| 360 | pg_version=pg_version, extra_command=["-c", "max_replication_slots=3"] |
| 361 | ) |
| 362 | ): |
| 363 | c.up("materialized", "postgres", Service("testdrive", idle=True)) |
| 364 | |
| 365 | # Set up the Postgres server with the initial records, set up the connection to |
| 366 | # the Postgres server in Materialize. |
| 367 | c.testdrive(dedent(""" |
| 368 | $ postgres-execute connection=postgres://postgres:postgres@postgres |
| 369 | ALTER USER postgres WITH replication; |
| 370 | DROP SCHEMA IF EXISTS public CASCADE; |
| 371 | DROP PUBLICATION IF EXISTS mz_source; |
| 372 | CREATE SCHEMA public; |
| 373 | |
| 374 | > CREATE SECRET IF NOT EXISTS pgpass AS 'postgres' |
| 375 | > CREATE CONNECTION IF NOT EXISTS pg TO POSTGRES (HOST postgres, DATABASE postgres, USER postgres, PASSWORD SECRET pgpass) |
| 376 | |
| 377 | $ postgres-execute connection=postgres://postgres:postgres@postgres |
| 378 | DROP TABLE IF EXISTS products; |
| 379 | CREATE TABLE products (id int NOT NULL, name varchar(255) DEFAULT NULL, merchant_id int NOT NULL, price int DEFAULT NULL, status int DEFAULT NULL, created_at timestamp NULL, recordSizePayload text, PRIMARY KEY (id)); |
| 380 | ALTER TABLE products REPLICA IDENTITY FULL; |
| 381 | CREATE PUBLICATION mz_source FOR ALL TABLES; |
| 382 | |
| 383 | > DROP SOURCE IF EXISTS s1 CASCADE; |
| 384 | """)) |
| 385 | |
| 386 | def make_inserts(c: Composition, start: int, batch_num: int): |
| 387 | c.testdrive( |
| 388 | args=["--no-reset"], |
| 389 | input=dedent(f""" |
| 390 | $ postgres-execute connection=postgres://postgres:postgres@postgres |
| 391 | INSERT INTO products (id, name, merchant_id, price, status, created_at, recordSizePayload) SELECT {start} + row_number() OVER (), 'name' || ({start} + row_number() OVER ()), ({start} + row_number() OVER ()) % 1000, ({start} + row_number() OVER ()) % 1000, ({start} + row_number() OVER ()) % 10, '2024-12-12'::DATE, repeat('x', 1000000) FROM generate_series(1, {batch_num}); |
| 392 | """), |
| 393 | ) |
| 394 | |
| 395 | num_rows = 100_000 # out of memory with 200_000 rows |
| 396 | batch_size = 10_000 |
| 397 | for i in range(0, num_rows, batch_size): |
| 398 | batch_num = min(batch_size, num_rows - i) |
| 399 | make_inserts(c, i, batch_num) |
| 400 | |
| 401 | # Update pg_class.relpages so Materialize's ctid-based parallel snapshot |
| 402 | # can partition across workers from the first read. |
| 403 | c.testdrive( |
| 404 | args=["--no-reset"], |
| 405 | input=dedent(""" |
| 406 | $ postgres-execute connection=postgres://postgres:postgres@postgres |
| 407 | ANALYZE products; |
| 408 | """), |
| 409 | ) |
| 410 |
nothing calls this directly
no test coverage detected