PostgreSQL 9.3 has lot of new improvement like the addition of new operators for JSON data type in postgreSQL, that prompted me to explore its features for NoSQL capabilities.
MongoDB is one of NoSQL solutions that have gotten a great deal of attention in the NoSQL market. So, this time I thought to do some benchmarking with the NoSQL capability of JSON in MongoDB and the JSON datatype in PostgreSQL 9.3
For this benchmark, I have used the same machine with no optimization in installation of PostgreSQL and MongoDB (since I wanted to see how things work, out of box with default installation). And I used the sample data from MongoDB’s site, around which I had developed the functions which can generate random data using the same sample for Mongo and for PostgreSQL.
In this benchmarking, I have verified following:
1. PostgreSQL COPY Vs Mongo-Import
2. Data Disk Size of PostgreSQL and Mongo for same amount of data.
3. PostgreSQL INSERT Vs Mongo Insert
Some specification before I would display the result:
1. Operating System: CentOS 6.5, 64 bit.
2. Total Memory: 1.538 GB
3. MongoDB version: 2.4.9
4. PostgreSQL: 9.3
Below is the results which I have got:
For Bulkload (COPY Vs MongoImport):
# of rows 1000 10000 100000 1000000 mongo-import (ms) 86.241679 569.761325 6940.837053 68610.69793 PG COPY (ms) 27.36344 176.705094 1769.641917 24801.23291
Disk space utilization:
# of rows 1000 10000 100000 1000000 mongo disks (mb) 208 208 208.2033236 976 pg size (mb) 0.3515625 3.2890625 32.71875 326.8984375
# of Inserts 1000 10000 100000 1000000 MONGO INSERTS (sec) 0.521397404 4.578372454 43.92753611 449.4023542 PG INSERTS (sec) 0.326254529 4.169742939 32.21799302 319.2562722
If you look at above stats, you can see PostgreSQL JSON is much better in bulk loading and INSERTs.
Best thing is that it takes less space than MongoDB and doesn’t eat up much disk space.