Why is database cache not used by Firebird with my web application?


Firebird loads the page cache upon first attachment (connection) to the database. When the last client disconnects, the memory used by cache is freed. This can be a problem with web applications (PHP, ASP, ...) that have short transactions in a 'connect-execute-disconnect' style, but also with regular appplications that don't keep the connection open. The problem is not noticeable on Linux as the operating system caches the filesystem in memory even after the application exists. However, on Windows, the memory is released instantly, and data needs to be loaded from the disk each time.

If you use Windows, you can work around this problem by having a single connection that does nothing: just connect and sit there - don't start a transaction as it would make your tranasction gap growing. Please note that many tools and libraries start implicit transaction when you log in, so you better use something that doesn't do that.

On Linux, it is wise to reduce the DefaultDbCachePages setting in firebird.conf to lessen the number of pages that are preloaded at each connection - filesystem would cache the often used pages anyway.

Some of the connection libraries offer persistent connections. For example, in PHP you can use ibase_pconnect instead of ibase_connect. Nigel Weeks pointed to us that when using this on a Unix machine wich Apache in PreFork mode, it will start up a Firebird Classic process for each Apache process thatís running. Since this is Classic, each process will maintain it's own database cache, so make sure you limit the number of concurrent Apache processes that can run.


Do you find this FAQ incorrect or incomplete? Please e-mail us what needs to be changed. To ensure quality, each change is checked by our editors (and often tested on live Firebird databases), before it enters the main FAQ database. If you desire so, the changes will be credited to your name. To learn more, visit our add content page.

If you are a commercial tool maker and your tool features a great way to handle the issue written about in this FAQ, please check out our advertisement page.



All contents are copyright © 2007-2017 FirebirdFAQ.org unless otherwise stated in the text.


Links   Firebird   News   FlameRobin   Home Inventory powered by FB  
Add content   Advertise   About  

Categories
 Newbies
 SQL
 Installation and setup
 Backup and restore
 Performance
 Security
 Connectivity and API
 HOWTOs
 Errors and error codes
 Miscellaneous