Hi,
I’ve run a couple of pgbenchmarks using this patch with odyssey connection pooler, with client-to-pooler ZSTD compression turned on.
pgbench --builtin tpcb-like -t 75 --jobs=32 --client=1000
CPU utilization chart of the configuration above:
https://storage.yandexcloud.net/usernamedt/odyssey-compression.png
CPU overhead on average was about 10%.
pgbench -i -s 1500
CPU utilization chart of the configuration above:
https://storage.yandexcloud.net/usernamedt/odyssey-compression-i-s.png
As you can see, there was not any noticeable difference in CPU utilization with ZSTD compression enabled or disabled.
Regarding replication, I've made a couple of fixes for this patch, you can find them in this pull request https://github.com/postgrespro/libpq_compression/pull/3
With these fixes applied, I've run some tests using this patch with streaming physical replication on some large clusters. Here is the difference of network usage on the replica with ZSTD replication compression enabled compared to the replica without replication compression:
- on pgbench -i -s 1500 there was ~23x less network usage
- on pgbench -T 300 --jobs=32 --client=640 there was ~4.5x less network usage
- on pg_restore of the ~300 GB database there was ~5x less network usage
To sum up, I think that the current version of the patch (with per-connection compression) is OK from the protocol point of view except for the compression initialization part. As discussed, we can either do initialization before the startup packet or move the compression to _pq_ parameter to avoid issues on older backends.
Regarding switchable on the fly compression, although it introduces more flexibility, seems like that it will significantly increase the implementation complexity of both the frontend and backend. To support this approach in the future, maybe we should add something like the compression mode to protocol and name the current approach as “permanent” while reserving the “switchable” compression type for future implementation?
Thanks,
Daniil Zakhlystov