WiseLibs / better-sqlite3

The fastest and simplest library for SQLite3 in Node.js.
MIT License
5.26k stars 391 forks source link

Safety under cluster mode #1068

Closed fabiospampinato closed 10 months ago

fabiospampinato commented 10 months ago

Node has a cluster module for having multiple instances of an app share the same HTTP ports for example, to spread the load across multiple cores.

Is better-sqlite3 safe to use under that environment? Asking just to be sure, as sometimes there are problems with these things.

mceachen commented 10 months ago

Make sure you're using WAL mode. If you've only got a couple processes and the database is <100Mb, you should be fine. Larger databases and 5+ processes with heavy write loads and I'd expect issues.

fabiospampinato commented 10 months ago

What kinds of issues? Like a corrupted database or what else exactly?

JoshuaWise commented 10 months ago

What kinds of issues? Like a corrupted database or what else exactly?

Performance issues. It's perfectly safe to access the same SQLite database from multiple processes, but performance may suffer if all processes are trying to write to the database at the same time.