Postgres can run locally, communicating via a Unix socket. You should try benchmarking this before stating that it's so much slower than SQLite.
Postgres can run locally, communicating via a Unix socket. You should try benchmarking this before stating that it's so much slower than SQLite.
kernel (filesystem) -> app with SQLite library
kernel (filesystem) -> Postgres -> kernel -> app with Postgres client
If Postgres reads data from own cache (not from disk) the chain will be one step shorter: Postgres -> kernel -> client, but the same true for SQLite own cache.If mmap is used (make sense for small data sets cached in RAM) then reading data by SQLite can be zero-copy [1].
Benchmark result highly depends on a use case - neither is better for all use cases but at least for some use cases SQLite is faster.
1. create the ramdisk
2. mount the ramdisk, configure systemd to automount it
3. modify the systemd unit file for psql to depend on the ramdisk
4. initialize all the psql data structures in the ramdisk mount folder
No clue what Postgres would manage, but I suspect it would be about an order of magnitude higher latency in the happy case.
Unless you’re talking 1 versus 10 microseconds (or less), I don’t think Postgres will have an order of magnitude higher latency. And if we are talking this range, why would it matter for a web app where the client’s latency is almost certainly >1 millisecond?
With SQLite, it's often practical to issue several queries in situations where that would be too slow for a traditional client-server database.
Which is already IPC, which already makes it slower than having the data never crossing process boundaries. No benchmark required.
$ pgbench -h localhost -p 5432 -b select-only -T 60 -c 10 -j 2 bench
Password:
pgbench (15.3 (Ubuntu 15.3-1.pgdg22.04+1))
starting vacuum...end.
transaction type: <builtin: select only>
scaling factor: 1
query mode: simple
number of clients: 10
number of threads: 2
maximum number of tries: 1
duration: 60 s
number of transactions actually processed: 10370147
number of failed transactions: 0 (0.000%)
latency average = 0.058 ms
initial connection time = 54.881 ms
tps = 172993.008029 (without initial connection time)
$ pgbench -h /var/run/postgresql -p 5432 -b select-only -T 60 -c 10 -j 2 bench
pgbench (15.3 (Ubuntu 15.3-1.pgdg22.04+1))
starting vacuum...end.
transaction type: <builtin: select only>
scaling factor: 1
query mode: simple
number of clients: 10
number of threads: 2
maximum number of tries: 1
duration: 60 s
number of transactions actually processed: 16890415
number of failed transactions: 0 (0.000%)
latency average = 0.036 ms
initial connection time = 7.186 ms
tps = 281540.260418 (without initial connection time)
YMMV depending on your workload, but Unix sockets should always be significantly faster.