Skip to content

Commit ab07f18

Browse files
committed
Rename PG Bouncer to PG Event Distributor
1 parent cc68ed0 commit ab07f18

File tree

7 files changed

+57
-57
lines changed

7 files changed

+57
-57
lines changed

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ The repository is hosted on `github <https://github.com/janbjorge/PGCacheWatch>`
1818
setup
1919
configuration
2020
strategies
21-
pgb
21+
pged
2222
examples

docs/pgb.md

Lines changed: 0 additions & 44 deletions
This file was deleted.

docs/pged.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
## PG Event Distributor
2+
3+
The PG event distributor, is designed to enhance PGCacheWatch by enabling efficient distribution of PostgreSQL notifications to multiple clients. This service acts as a middleware, receiving notifications from PostgreSQL and broadcasting them to connected clients via WebSockets. This "fan-out" effect ensures real-time cache invalidation across all clients with minimal database connections.
4+
5+
### Key Benefits:
6+
7+
- **Scalability**: Handles numerous clients without increasing load on the PostgreSQL server.
8+
- **Efficiency**: Reduces the need for multiple direct connections to PostgreSQL for NOTIFY/LISTEN.
9+
- **Real-time**: Ensures immediate cache invalidation across services upon database changes.
10+
11+
### Illustration:
12+
13+
```
14+
+-------------------+
15+
| PostgreSQL DB |
16+
| - NOTIFY on event |
17+
+---------+---------+
18+
|
19+
| NOTIFY
20+
|
21+
+---------v-------------+
22+
| PG Event Distributor |
23+
| Service |
24+
| - Fan-out NOTIFY |
25+
+---------+-------------+
26+
|
27+
+-------------+-------------+
28+
| |
29+
+-------v-------+ +-------v-------+
30+
| WebSocket | | WebSocket |
31+
| Client 1 | | Client N |
32+
| - Invalidate | | - Invalidate |
33+
| Cache | | Cache |
34+
+---------------+ +---------------+
35+
```
36+
37+
To leverage the PG Event Distributor within your PGCacheWatch setup, ensure it's running and accessible by your application. Configure PGCacheWatch to connect to the PG Event Distributor instead of directly to PostgreSQL for notifications. This setup amplifies the effectiveness of your cache invalidation strategy by ensuring timely updates across all client caches with optimized resource usage.
38+
39+
### Running the PG Event Distributor
40+
To start the PG Event Distributor service, use the following command in your terminal. This command utilizes uvicorn, an ASGI server, to run the service defined in the `pgcachewatch.pg_event_distributor:main` module. The --factory flag is used to indicate that uvicorn should call the provided application factory function to get the ASGI application instance.
41+
42+
```bash
43+
uvicorn pgcachewatch.pg_event_distributor:main --factory
44+
```

src/pgcachewatch/pg_bouncer.py renamed to src/pgcachewatch/pg_event_distributor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
among multiple clients
55
66
Usage example:
7-
`uvicorn pgcachewatch.pg_bouncer:main --factory`
7+
`uvicorn pgcachewatch.pg_event_distributor:main --factory`
88
"""
99

1010
import asyncio

tests/conftest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def pgb_address() -> str:
1414
return "127.0.0.1:8000"
1515

1616

17-
async def pg_bouncer_isup() -> bool:
17+
async def pg_event_distributor_isup() -> bool:
1818
timeout = timedelta(seconds=1)
1919
deadline = datetime.now() + timeout
2020

@@ -61,13 +61,13 @@ def set_pg_envs(monkeypatch: pytest.MonkeyPatch) -> None:
6161

6262

6363
@pytest.fixture(scope="function")
64-
async def pgbapp() -> AsyncGenerator[Popen, None]:
64+
async def pgedapp() -> AsyncGenerator[Popen, None]:
6565
with Popen(
66-
"uvicorn pgcachewatch.pg_bouncer:main --factory".split(),
66+
"uvicorn pgcachewatch.pg_event_distributor:main --factory".split(),
6767
stderr=PIPE,
6868
stdout=PIPE,
6969
) as p:
70-
await pg_bouncer_isup()
70+
await pg_event_distributor_isup()
7171
try:
7272
yield p
7373
finally:

tests/test_listeners.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ async def test_eventqueue_and_pglistner(
4848
@pytest.mark.parametrize("N", (1, 8, 32))
4949
@pytest.mark.parametrize("operation", get_args(models.OPERATIONS))
5050
async def test_eventqueue_and_wslistner(
51-
pgbapp: Popen,
51+
pgedapp: Popen,
5252
N: int,
5353
operation: models.OPERATIONS,
5454
pgpool: asyncpg.Pool,

tests/test_pg_bouncer.py renamed to tests/test_pg_event_distributor.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66
import asyncpg
77
import pytest
88
import websockets
9-
from conftest import pg_bouncer_isup, pgb_address
9+
from conftest import pg_event_distributor_isup, pgb_address
1010
from pgcachewatch import listeners, models, utils
1111

1212

13-
async def test_up_endpoint(pgbapp: Popen) -> None:
14-
assert await pg_bouncer_isup()
13+
async def test_up_endpoint(pgedapp: Popen) -> None:
14+
assert await pg_event_distributor_isup()
1515

1616

1717
@pytest.mark.parametrize("operation", get_args(models.OPERATIONS))
1818
@pytest.mark.parametrize("N", (1, 8))
1919
async def test_ws_broadcast(
20-
pgbapp: Popen,
20+
pgedapp: Popen,
2121
N: int,
2222
pgpool: asyncpg.Pool,
2323
operation: models.OPERATIONS,
@@ -99,7 +99,7 @@ async def test_put_ws_event_queue(
9999
@pytest.mark.parametrize("operation", get_args(models.OPERATIONS))
100100
@pytest.mark.parametrize("N", (1, 64))
101101
async def test_put_on_event_ws_event_queue(
102-
pgbapp: Popen,
102+
pgedapp: Popen,
103103
N: int,
104104
pgpool: asyncpg.Pool,
105105
operation: models.OPERATIONS,
@@ -133,7 +133,7 @@ async def test_put_on_event_ws_event_queue(
133133

134134

135135
async def test_ws_event_queue_connection_healthy(
136-
pgbapp: Popen,
136+
pgedapp: Popen,
137137
channel: models.PGChannel = models.PGChannel(
138138
"test_ws_event_queue_connection_healthy"
139139
),

0 commit comments

Comments
 (0)