75 points · by rick446 · 14y ago · 73 comments
I've never taken time to see what MogoDB db is, but thanks to this opening sentence, now I know everything I ever wanted to know about this system. Having worked for 13 years on database system design I am pretty confident that a system not designed with concurrency in mind cannot be retrofitted with any decent concurrency later.
Thank you Rick for saving me the time.
That operating system is Linux. It started out very simple and was good enough for many people and then kept evolving. Nowadays the alternatives are mainly footnotes in history.
MongoDB is also simple. Its locking approach does not give wrong answers. Its users are happy. Your assertion that the locking can't evolve is bollocks because you have no clue how the database works. While your statement has many elements of truth for a relational database, it is meaningless for the current generation of schemaless/NoSQL databases. Did you know that MongoDB has auto-sharding and replication, and doesn't need locks for that either?
How about I call it a tool that holds your data for you and gives it back later. This tool has certain properties that make it work (or not work) for certain applications. It is just that simple.
I do not work with/for 10gen but we have been using MongoDB since version 1.5 and found it incredibly useful addition to our toolbox. It always helps to own more than one hammer.
Fine, I'll bite.
Your assertion that MongoDB was not designed "with concurrency in mind" is simply wrong. They have in fact put a lot of thought into it, they simply made decisions that you either do not understand, or happen to disagree with.
Nobody at 10gen is arguing that a global write lock is the best idea in the world. They are acutely aware of the drawbacks. They initially implemented it that way because it significantly reduces the complexity of offering concurrency in the first place. There's a reason that a NoSQL solution with more granular locking doesn't exist yet. It's much more difficult to construct. There is an ongoing, documented, transparent effort to migrate toward more granular locking, but that is hard and takes time. In the meantime, they have been working on mitigating the drawbacks of their decision by aggressively yielding whenever possible during long running operations.
Did you even read the article? Did you look at the benchmarks? The entire point of it was it's not as bad as you would think, and it's getting better.
In other words, your analytical faculties have been intentionally shut down.
I am pretty confident that a system not designed with concurrency in mind cannot be retrofitted with any decent concurrency later.
I think you're probably right from a software engineering perspective. But you haven't actually shown that Mongo was "not designed with concurrency in mind".
I've implemented in-memory persistent storage systems with a global RW lock. Depending on the characteristics of the load it can be ridiculously fast. E.g., on the order of tens of microseconds for typical transactions.
Complex schemes like MVCC with multimaster replication are an amazing accomplishment and are great for general purpose SQL-driven databases. But it's not the only reasonable design choice in the world and it's certainly not the optimal one for every problem.
For a sign of things to come, I invite you to take a look at how relational database vendors are fighting to squeeze single-digit percentages from their engines to beat benchmarks such as TPC-C or TPC-E. NoSQL will get there too - fight for efficiency.
Did you really read the post before arguing this?
mongod threads yield their lock (read or write) in two classes of situations:
* yield-on-page-fault – v2.0 implements a yield-on-page-fault feature which results in much more concurrency than one would achieve with a pure reader/writer lock. For common operational cases, file system page faults are detected in advanced and handled outside of any lock, then the lock is resumed. Not all fault situations yield, but many do. This results in v2.0 having much better concurrency in practice than v1.8.
* yield-on-long-operation – mongod also yields periodically on common operations that are extremely long running. The goal here is to allow interleaving so that other operations which are quick-running can execute soon.
http://www.mongodb.org/display/DOCS/How+does+concurrency+wor...
And there's where your legacy understanding fails. You're really not supposed to be doing a lot of disk IO in modern datastores in the first place. Your working set should be in RAM.
> beat benchmarks
If my vendor is investing time in beating benchmarks instead of solving real problems, I'm finding a new vendor.
it was designed with concurrency in mind, the concurrency you're looking for comes in the form of sharding and replica sets though.
edit: meh, got bored, decided to defend it: http://news.ycombinator.com/item?id=3412283
Actually, it does affect you. I have worked with mongodb in production in a high-write scenario with about 1000 clients and it slowed to a crawl. All data was in memory. The server was not breaking much of a sweat. mongostat showed upwards of 60 queued reads/writes at any given time.
The only solution was to shard, but I feel like an enormous server like the one we were using should be able to handle 1000 writing clients.
Keep in mind this was version 1.8. I no longer work at the company where this happened and cannot testify to the performance of 2.0, but 1.8 has abysmal write performance.
To name a few,
* word-unaligned memory structures, which leads to incompatibility with virtually any non-x86 CPU architecture
* explicitly little-endian processing in the server, so there is no way to run the original code on any big-endian CPU architecture.
There has been a patchset which was tested on a SPARC CPU, but last time I asked the author, the 10gen team completely ignored this effort.
apart from that, there have been reports of data loss without any failure note
> It has been criticized a lot [...] but still for some reason it's so popular
Since you provide no data or sources for "criticized a lot" it's no surprise that you don't provide the same for "so popular". I assume you mean "I've seen some headlines on Hacker News about it".
> incompatibility with virtually any non-x86 CPU architecture [...] no way to run the original code on any big-endian CPU architecture
Huh. Maybe that's only a problem for people on non-x86 CPUs then?
Look I'm really not a fan of Mongo but "It has been criticized a lot [...] but still for some reason it's so popular" describes every technology ever. Get over it.
1. Look at their BSON format specification: http://bsonspec.org/#/specification They name it a new "standard", and at the same time they have things like "\x11" -> Timestamp, a special internal MongoDB data for replication. It's like the IP protocol specification would have vendor-specific parts.
2. The BSON format is not word-aligned, which makes it quite inefficient to process in memory. Besides, the current Mongo server accesses it with word-unaligned pointers, which is only possible on x86 architecture.
to me, it just tells that the database engine design was given to the wrong people.
there have been tons of discussions, also on HN, very easy to google
actually it's a problem for application developers. I cannot rely on a backend system with limitations like these. So I'll have to go back to the RDBMS backend or look for other nosql alternatives, but definitely mongoDB is off my list
Arguing everyone else should ditch code that happens to not work on your pet architecture is a pretty self-centered worldview.
Remember that if you run into scalability issues in the cloud all you have to do is spin up 300 instances to get the performance of one 5400 rpm laptop drive. The cloud is webscale your laptop is not. Also please ignore that a laptop with an ssd will need about 3000 instances to get the same performance.
Who would design a database so shitty that journalling the data impacts performance. Typically you only need one spindle for a journal to support 100 to 200 data spindles. If you can't pull 80 to 90 mb/sec sustained write from a log drive something is seriously wrong.
48 iops now that's what I call "web scale". Let me just throw out my acid database that does 30000 iops on Win2k3 of all things, to get 48 iops with out journalling.
Except that now with that new graph showing such good performance on reads during paging people are going to get confused.
Anyway you can get 32GB of RAM for $232 or 48GB for $636. Which means that for 90% of applications, you actually don't need to shard. And if the journaling works (people with a vested interest in relational systems really have to hope that it doesn't), then I don't have to worry about my data disappearing, even if I only have one database server, which is also not a recommended design with MongoDB (or any database really).
I have years of experience with SQL Server, Oracle and MySQL. However, MongoDB is the most attractive database now because it makes the object-relational impedance mismatch go away. http://en.wikipedia.org/wiki/Object-relational_impedance_mis...
If I can write code (in CoffeeScript using a library like Mongolian Deadbeef) like this
posts.insert
pageId: "hallo"
title: "Hallo"
body: "Welcome to my new blog!"
created: new Date
posts.findOne
pageId: "hallo"
, (err, post) ->
posts.find().limit(5).sort(created: 1).toArray (err, array) ->
then whey would I want to deal with separate steps of setting up the relational database tables, creating stored procedures, creating a software layer to map my objects to my tables etc., or hiring a DBA?I believe that most of the hate for MongoDB is fueled by a survival instinct. The popularity of databases like MongoDB threaten to make years of experience obsolete and threaten the existence of the DBA profession. Relational databases are great, but they were an optimization designed to solve certain problems that most people today just don't have, and now they have become an unfortunate institutionalized dogma.
Using K/V stores will only help you write data. But the whole impedance nightmare is right there, waiting for you to try and make some sense of the data. Especially if you want to do relations.
And you are dead wrong about relational DB's. It is either due to habit or because of being a better fit that users demand representations of data that are best served from a relational source. So you better plan your data models wisely, because you WILL pump this data into a relational source, sooner or later. It would be wise do keep a schema around all the time.
In the end it is merely a question of data normalization and the use case at hand.
Somewhat umbrella...but I do think that document-based storage does make a difference. It certainly doesn't erase it and, as you say, it varies based on the use-case at hand, but I think most people would consider the development experience to have less friction (and that's certainly been the overwhelming anecdotal evidence I've heard (and can give)).
My designs for use of MongoDB have always included my own versioned schema representation to be used, for starters, in generating data entry screens.
Which NoSQL databases did you use?
I know enough about MongoDB, that I know its not all that much different as far as design and usage patterns go. This link [1] tells me that basically mongo's data structure is indeed a Key/Value.
The schema you are talking about is not the schema I mean. What I was talking about that for any nontrivial Key/Value based database system it would be prudent to keep a recipe of how to normalize the data to 3rd Normal Form. Keeping this 3rd Normal Form schema around would greatly ease many troubles that arise from using NoSQL databases.
So what were you thinking about when you say "schema" - is it "relational" (normalized) schema or is it just the recipe that tells you what particular fields are for?
Can you elaborate?
I understand any JSON can be shredded into a third normal form (minus the ordering problem, but let's leave that aside for now), is this what you refer to?
The kosher way of designing document oriented database is to simply embed everything within a document. This is great for operations such as full text search, retrieving whole objects, etc. We call this denormalized form.
On the other hand, sometimes we want to analyze our data, e.g. we want to extract subsets of data and view them in isolation. With completely denormalized form this is expensive, since we either need to manually touch each and every document and extract data or we need to maintain indices that help us out. Both are extremely resource intensive.
The third option is that we chop our objects into smaller objects and then link them together. But this will mean that retrieving a whole document will take longer (multiple database requests) it also adds an overhead of eliminating duplicates (two objects may appear identical, but really are not), etc...
Denormalization gives you horizontal scalability, but takes away ad-hoc querying. It also wastes storage (document size is minor issue, Indices however will kill you [2]).
Normalized data will take away horizontal scalability, give you ad-hoc querying, and save storage space.
In the end for any kind of nontrivial system, you will eventually reach a point, where you will need to maintain two storages - a normalized and non-normalized form. The only difference is what your primary problem is and this sets whether you start out from Normalized or Denormalized storage, this will be your primary storage and source. The other kind will be an offline slave that will offer secondary functionality.
E.g: If you start out from relational data and you want to build a FTS, you WILL have to denormalize data. On the other hand, if you start from Object/Document store and want to offer ad-hoc analytics, you WILL have to normalize your data. Its good to keep it in the back of your head.
[1]: http://www.mongodb.org/display/DOCS/Schema+Design [2]: An application I worked on had 2GB (100 million documents) worth of data, however completely indexed database would take 25GB of storage and Index rebuild would take ~8 hours.
Really? What if you accidentally use 'createDate' instead of 'created' in one spot of your system. You'll get crap data and you won't even know! Or what if some other part of the system relies on a 'post' having a 'pageId' but there's no way to enforce it in your DB? It's called DATA CONSISTENCY and if you don't see the value in stuff like that then you've never worked on a system of significant size.
You NoSQL fans don't seem to realize that these 'separate steps' you don't want to 'deal with' arised from many decades of data storage experience in the real world. Ignore them at your peril.
A good solution for dealing with changing/varied schemas is to record multiple schema versions. This is the type of problem that will occur on small systems just as well as large ones, any time the requirements change, and of course how you handle those changes is a key aspect of your system design. And a relational setup has the same type of problem in keeping the requirements, schema, application and deployment in sync. I don't think I implied that there is no value in facilities for data consistency, and I did not mean to imply that a relational database cannot have some advantages, but overall for most cases my current belief is that there are more advantages, in most circumstances, especially if you are using something like CoffeeScript/Node.js, with MongoDB.
I'm only guessing but it seems to me that any database with their entire dataset in memory would be very fast, no?
I'm assuming MongoDB tries to detect this with OS-specific syscalls. Has there been any attempt to determine whether it would be even faster and/or more portable to just unconditionally "read" the pages before acquiring the lock?
Every now and again you'll see this approach get suggested in the groups.