Reputation: 1265
I just want to understand better, in what I have learned for years is a document based solution is slow and requires a lot of I/O. FOr example in a PHP project, it is generally said it is much much better to use a memory cache like Redis ,Memecache, or APC because they are memory based instead of caching data to an actual FILE.
Now all these NoSQL DB's have arrived and I read about how they are so much faster then MySQl and others and they are Document Based. Can someone help me understand this theory? If each record is a Document (FILE), then how is it so good on performance? I recently read about a guy who was using Redis in a project and said he switched to MongoDB and is having better results then he did with Redis (I realize I am comparing a Cache to a DB, but that is not the real question, I want to know how a Document based solution is faster then non-document based solutions?)
Upvotes: 9
Views: 3614
Reputation: 2275
One of the factors which make Document based db faster than the relational ones is Locality.
Documents are independent units:: which makes performance better (related data is read contiguously off disk) and makes it easier to distribute data across multiple servers while preserving its locality.
Upvotes: 1
Reputation: 2501
The magic ingredient isn't necessarily a "faster" database, it is a database which enables the design and implementation of "faster" systems. That is why NoSQL databases are considered a game-changer.
For several decades relational databases were the only game in town. Many SQL-based systems pay a double performance tax: once for the full ACID featureset (which they probably don't need anyway), and then again to shoehorn their domain data into a relational table model.
Also, one common trait of most NoSQL databases is that they are simpler due to their being more specialized than the "general case" approach of a SQL database. That means less logic/code which needs to run on each operation, simpler data structures (which may require less IO) and in general - less overhead, better performance.
Upvotes: 3
Reputation: 12412
To get an idea, consider this:
Although that one mongo query might be slower than one mysql query, comparing 1 mongo query to 100 mysql queries is going to be much faster.
Upvotes: 0
Reputation: 65274
The NoSQL speak can be prone to misunderstandings, as some of the concepts will use names, that have a different meaning to the traditional one:
Upvotes: 3
Reputation: 14782
Document Based doesn't necessarily mean they are stored entirely on file system. Some parts can still be held in memory like an index.
Document based only means the database stores data in packages (like sheets of paper where every sheet is a dataset and you can write freely on it) instead of a very specific structure like a table.
http://en.wikipedia.org/wiki/Document-oriented_database
Ah and why they can be faster than redis:
Let's say you need to store some non-linear information in a set (i.e. not every dataset looks the same and you got different datatypes in one set. On Redis you can only store key-value pairs so you will need so link them back together to a set in your own code/implementation. On a NoSQL Database this is handled for you by the database in a (probably) much more optimized way :)
Upvotes: 5
Reputation: 1464
First thing is - you can't compare the NoSQL DBs to in-memory DBs. NoSQL DBs are ment for data that won't fit in the memory.
Now, regarding the NoSQL DBs, they are not just simple files, they have indexes that provide fast access to offsets in the files and that is where the speed really is.
Upvotes: 0