I'm trying to figure out how to limit SQLite's memory usage while still
giving it as much memory as I can.

The app has about 50-60 separate database handles to 50-60 separate database
files.  Each handle is only used by a single thread at a time, and most are
always accessed by the thread that created the handle.

When each handle is created, I execute:
PRAGMA temp_store=1  { can't tell from the docs if this needs to be executed
on each handle or not }
PRAGMA page_size=4096
PRAGMA cache_size= { either 2000 or 6000 depending on the database file
being opened }

So in theory, my cache usage could be anywhere from 50 * 4KB * 2000 =
400,000 KB to 60 * 4KB * 6000 = 1,440,000 KB.

The 1.4 Gig'ish number is too large for the process to handle - I need to
limit it to about 1GB.

Currently I'm calling   sqlite3_soft_heap_limit(1024 * 1024 * 1024) with the
hope that if memory needs to be allocated there should be plenty
(60*6000=360,000) of pages that sqlite3_release_memory could release and
thus the soft limit would hold.  Apparently I'm wrong though -
sqlite3_memory_used is reporting 1,266,186 KB.

Is there a better way to go about it?  I can limit the cache_size value, but
I'd like to optimize and use as much memory, up to the limit, as I can.
Shared cache seems like it might be an option, but there are enough caveats
and considerations that I don't feel I understand it well enough to risk it.

I'm open to any suggestions.

Thanks


_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to