scale.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. from textwrap import dedent
  10. from materialize.feature_benchmark.measurement_source import MeasurementSource, Td
  11. from materialize.feature_benchmark.scenario import Scenario
  12. class SmallClusters(Scenario):
  13. """Materialized views across many small clusters."""
  14. SCALE = 1.5 # 32 clusters
  15. FIXED_SCALE = True
  16. def benchmark(self) -> MeasurementSource:
  17. create = "\n".join(
  18. dedent(
  19. f"""
  20. > DROP CLUSTER IF EXISTS cluster{i} CASCADE;
  21. > CREATE CLUSTER cluster{i} REPLICAS (r (SIZE '4-1'));
  22. > CREATE MATERIALIZED VIEW v{i}
  23. IN CLUSTER cluster{i}
  24. AS SELECT COUNT(*) FROM t1;
  25. > CREATE DEFAULT INDEX ON v{i}
  26. """
  27. )
  28. for i in range(self.n())
  29. )
  30. # We wait until all clusters are booted and connected before starting
  31. # the time measurement. This is to avoid flakiness caused by the retry
  32. # backoff the controller uses on replica connection attempts.
  33. wait = "\n".join(
  34. dedent(
  35. f"""
  36. > SET CLUSTER = cluster{i}
  37. > SELECT * FROM v{i}
  38. 0
  39. """
  40. )
  41. for i in range(self.n())
  42. )
  43. select = "\n".join(
  44. dedent(
  45. f"""
  46. > SET CLUSTER = cluster{i}
  47. > SELECT * FROM v{i}
  48. 1000000
  49. """
  50. )
  51. for i in range(self.n())
  52. )
  53. return Td(
  54. dedent(
  55. f"""
  56. > DROP TABLE IF EXISTS t1 CASCADE;
  57. > CREATE TABLE t1 (f1 INTEGER);
  58. $ postgres-execute connection=postgres://mz_system:materialize@${{testdrive.materialize-internal-sql-addr}}
  59. ALTER SYSTEM SET max_clusters = {self.n() + 2};
  60. """
  61. )
  62. + create
  63. + wait
  64. + dedent(
  65. """
  66. > INSERT INTO t1
  67. SELECT * FROM generate_series(1, 1000000)
  68. /* A */
  69. """
  70. )
  71. + select
  72. + dedent(
  73. """
  74. > SELECT 1
  75. /* B */;
  76. 1
  77. """
  78. )
  79. )