views:

501

answers:

8

I'm considering using sqlite as a production database for a site that would receive perhaps 20 simultaneous users but with the potential for a peak that could be many multiples of that (since the site would be accessible on the open internet and there's always a possibility that someone will post a link somewhere that could drive many people to the site all at once).

Is sqlite a possibility?

I know it's not an ideal production scenario.

I'm only asking if this is within the realm of being a realistic possibility.

A: 

I think it would depend mostly on what your read/write ratio will be. If it's mostly reading from the database, you may be okay. Multi-user writing in SQLite can be a problem because of how it locks the database.

Adam Ruth
Do you mean if there is an attempt to do two simultaneous writes, it will lock until one completes and then let the other through? That doesn't sound like a problem for the data integrity but more about speed. Given the low traffic volumme, it might be tolerable.
carson welsh
It won't block but return SQLITE_BUSY. It's up to the application to decide how to proceed from there, e.g. wait a while and try again or give up and return an error.
laalto
+2  A: 

SQLite doesn't support any kind of concurrency, so you may have problems running it on a production website. If you're looking for a 'lighter' database, perhaps consider trying a contemporary object-document store like CouchDB.

By all means continue to develop against SQLlite, and you're probably fine to use it initially. If you find your application has more users down the track, you're going to want to transition to postgres or mysql however.

The author of SQLlite addresses this on the website:

SQLite usually will work great as the database engine for low to medium traffic websites (which is to say, 99.9% of all websites). The amount of web traffic that SQLite can handle depends, of course, on how heavily the website uses its database. Generally speaking, any site that gets fewer than 100K hits/day should work fine with SQLite. The 100K hits/day figure is a conservative estimate, not a hard upper bound. SQLite has been demonstrated to work with 10 times that amount of traffic.

SQLite will normally work fine as the database backend to a website. But if you website is so busy that you are thinking of splitting the database component off onto a separate machine, then you should definitely consider using an enterprise-class client/server database engine instead of SQLite.

So I think the long and short of it is, go for it, and if it's not working well for you, making the transition to an enterprise class database is fairly trivial anyway. Do take care over your scheme however, and design your database with growth and efficiency in mind.


Here's a thread with some more independent comments around using SQLite for a production web application. It sounds like it has been used with some mixed results.

From personal experience, I remember back in the dark days of web development using MS Access and Filemaker Pro that file locking was a persistent and painful problem. SQLlite may handle this more elegantly, but essentially it's the same problem, and I doubt much would have changed.

Bayard Randel
Speed problems? But with so few users I don't know if it's really an issue even if it doesn't allow concurrency. (I'm only interested in relational databases)
carson welsh
Interesting quote. Too bad it's not from a more independent source than the author of Sqlite himself. I'd prefer to see some outside verification.
carson welsh
I think he's being pretty frank - he does acknowledge that the web is not an ideal application for SQLlite.
Bayard Randel
That slidehost thread was a good discussion, particularly this: "Think of a blog, for example. Because multiple users can comment on a single post, multiple concurrent writes aren't that far-fetched. If your blog does not have commenting capabilities, however, there's likely a small chance that two writes will occur at once (unless you have a fair number of authors). So, think about the possible use cases. If there is indeed a chance that two or more users will be writing to the database at a time then I'd avoid SQLite. For more on locking and concurrency: http://www.sqlite.org/lockingv3.html"
carson welsh
I think your post does raise an interesting question though - there really isn't anything filling that gap between single file stores like berkelydb/sqllite, and more enterprise solutions like mysql and postgres. MySQL certainly used to be quite lean, but over the years has introduced features common accross enterprise DBs.
Bayard Randel
That's an insightful observation. Hadn't thought about that either.
carson welsh
A: 

Depends on the usage of the site. If most of the time you're just reading data, you can pretty much use anything for a DB and cache the data in the application to achieve good performance.

Badaro
That's a big 'if'. What if that's not true?
carson welsh
If it's not true, the "with the potential for a peak that could be many multiples" clause in your question would make the situation risky.We both have our doubts if SQLLite is up to the task, which is why I suggested caching in the first place: To avoid being too dependent on its performance if you get a big increase in hits.
Badaro
I see. But I'm not crazy about the idea of approximating database functionality in my app. I'd rather leave that work to the database.
carson welsh
You don't need to go that far. I was talking more in the lines of caching the processed data your views need for rendering, or even the HTML output if possible.
Badaro
+1  A: 

I'd avoid making overly conservative assumptions about any website's traffic in general and I would definitely avoid SQLite for a production database on a web server where you never know what kind of traffic you may have.

If you're interested in very low footprint, totally self-managed database systems, I can recommend Sybase SQL Anywhere. There's a free web edition.

Vincent Buck
That's an interesting option. Thanks for the link.
carson welsh
+1  A: 

We often use SQLite for internal databases; The employee directory, our calendar of events, and other intranet services all run on lightweight databases. It would be major overkill to be running these apps at the scale we do on a "real" database like mySQL. This is especially true when you factor in that they're running along side 4 other virtual machines on a single mid-range computer.

At one point we had an outward facing site that ran on an sqlite db for months with only a single reboot required. Obviously, it was very low traffic, but it putted along nicely for what it did.

Soviut
That's great to know. Thanks. I'm starting to get comfortable with the idea after reading a lot of positive feedback like this.
carson welsh
A: 

If it was me - I'd just use MySQL. We can be too precious about these things. I've had MySQL running on a NetGear ReadyNAS which has very limited memory (256 MB RAM I think) and a 32 MHz (you read that right) processor. It's fine. I've had it running on a low end Windows PC with about a 200 MHz processor and little RAM. Both cases serving web pages. Admittedly not with 20 simultaneous users.

But, in principle, if your hardware is reasonable and the database content is not ridiculously large, something like MySQL is free, easy to use and setup, fast, seems to scale well. I'd just go for that and devote my precious time to something else.

The environment I'm considering may not permit the installation of MySql.
carson welsh
A: 

I am using it in a very low traffic web server (it is a genomic database) and I don't have any problems. But there are only SELECT statements, no writing to the DB involved.

BlogueroConnor
A: 

People speack about concurrency problems, but sqlite has a way to cache the incoming requests and have them wait for some time. It doesn't timeout immediately?

I've read things about the default timeout setting begin zero, meaning it times out immediately and that's a nonsense. Maybe people didn't adjust this setting?

Thomas