mirror of
https://github.com/neondatabase/neon.git
synced 2026-05-22 15:41:15 +00:00
Add hot page test (#1479)
This commit is contained in:
@@ -130,7 +130,10 @@ class VanillaCompare(PgCompare):
|
||||
def __init__(self, zenbenchmark, vanilla_pg: VanillaPostgres):
|
||||
self._pg = vanilla_pg
|
||||
self._zenbenchmark = zenbenchmark
|
||||
vanilla_pg.configure(['shared_buffers=1MB'])
|
||||
vanilla_pg.configure([
|
||||
'shared_buffers=1MB',
|
||||
'synchronous_commit=off',
|
||||
])
|
||||
vanilla_pg.start()
|
||||
|
||||
# Long-lived cursor, useful for flushing
|
||||
|
||||
@@ -1315,7 +1315,7 @@ class VanillaPostgres(PgProtocol):
|
||||
"""Append lines into postgresql.conf file."""
|
||||
assert not self.running
|
||||
with open(os.path.join(self.pgdatadir, 'postgresql.conf'), 'a') as conf_file:
|
||||
conf_file.writelines(options)
|
||||
conf_file.write("\n".join(options))
|
||||
|
||||
def start(self, log_path: Optional[str] = None):
|
||||
assert not self.running
|
||||
|
||||
36
test_runner/performance/test_hot_page.py
Normal file
36
test_runner/performance/test_hot_page.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import pytest
|
||||
from contextlib import closing
|
||||
from fixtures.compare_fixtures import PgCompare
|
||||
from pytest_lazyfixture import lazy_fixture # type: ignore
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"env",
|
||||
[
|
||||
# The test is too slow to run in CI, but fast enough to run with remote tests
|
||||
pytest.param(lazy_fixture("zenith_compare"), id="zenith", marks=pytest.mark.slow),
|
||||
pytest.param(lazy_fixture("vanilla_compare"), id="vanilla", marks=pytest.mark.slow),
|
||||
pytest.param(lazy_fixture("remote_compare"), id="remote", marks=pytest.mark.remote_cluster),
|
||||
])
|
||||
def test_hot_page(env: PgCompare):
|
||||
# Update the same page many times, then measure read performance
|
||||
num_writes = 1000000
|
||||
|
||||
with closing(env.pg.connect()) as conn:
|
||||
with conn.cursor() as cur:
|
||||
|
||||
# Write many updates to the same row
|
||||
with env.record_duration('write'):
|
||||
cur.execute('create table t (i integer);')
|
||||
cur.execute('insert into t values (0);')
|
||||
for i in range(num_writes):
|
||||
cur.execute(f'update t set i = {i};')
|
||||
|
||||
# Write 3-4 MB to evict t from compute cache
|
||||
cur.execute('create table f (i integer);')
|
||||
cur.execute(f'insert into f values (generate_series(1,100000));')
|
||||
|
||||
# Read
|
||||
with env.record_duration('read'):
|
||||
cur.execute('select * from t;')
|
||||
cur.fetchall()
|
||||
35
test_runner/performance/test_hot_table.py
Normal file
35
test_runner/performance/test_hot_table.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import pytest
|
||||
from contextlib import closing
|
||||
from fixtures.compare_fixtures import PgCompare
|
||||
from pytest_lazyfixture import lazy_fixture # type: ignore
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"env",
|
||||
[
|
||||
# The test is too slow to run in CI, but fast enough to run with remote tests
|
||||
pytest.param(lazy_fixture("zenith_compare"), id="zenith", marks=pytest.mark.slow),
|
||||
pytest.param(lazy_fixture("vanilla_compare"), id="vanilla", marks=pytest.mark.slow),
|
||||
pytest.param(lazy_fixture("remote_compare"), id="remote", marks=pytest.mark.remote_cluster),
|
||||
])
|
||||
def test_hot_table(env: PgCompare):
|
||||
# Update a small table many times, then measure read performance
|
||||
num_rows = 100000 # Slightly larger than shared buffers size TODO validate
|
||||
num_writes = 1000000
|
||||
num_reads = 10
|
||||
|
||||
with closing(env.pg.connect()) as conn:
|
||||
with conn.cursor() as cur:
|
||||
|
||||
# Write many updates to a small table
|
||||
with env.record_duration('write'):
|
||||
cur.execute('create table t (i integer primary key);')
|
||||
cur.execute(f'insert into t values (generate_series(1,{num_rows}));')
|
||||
for i in range(num_writes):
|
||||
cur.execute(f'update t set i = {i + num_rows} WHERE i = {i};')
|
||||
|
||||
# Read the table
|
||||
with env.record_duration('read'):
|
||||
for i in range(num_reads):
|
||||
cur.execute('select * from t;')
|
||||
cur.fetchall()
|
||||
Reference in New Issue
Block a user