Coder Social home page Coder Social logo

mongodb-seed's Introduction

Mongodb Seed Program for e-receipt

Measurement Result

  • test pc info
    • Acer Aspire E5-571G notebook
    • Intel i5 - 4210U, 1.70 GHz, 3 MB
    • 12GB RAM
    • Kingston A400 SATA 240G SSD
  • seed the test database with 1 million documents
    • note: this seeding takes ~15 minutes
    $ make build && ./mongodb-seed --password database_password
    
  • before create any indexes (except the default "_id"), query for "acctId" is very slow
    $ time mongo mongodb://localhost/database_name --username database_username --password database_password --quiet --eval 'db.Receipts.find({acctId:"100000000001"}).count()'
    107186
    real    3m50.448s
    user    0m0.089s
    sys     0m0.028s
    
  • create following invidual indexes can help query for "acctId" but not for "acctId" AND "outlet"
    • note: each createIndex() will take >4 minutes
    db.Receipts.createIndex({"acctId": 1})
    db.Receipts.createIndex({"outlet": 1})
    db.Receipts.createIndex({"txnTime": 1})
    $ time mongo mongodb://localhost/database_name --username database_username --password database_password --quiet --eval 'db.Receipts.find({acctId:"100000000001"}).count()'
    107186
    real    0m0.244s
    user    0m0.092s
    sys     0m0.021s
    $ time mongo mongodb://localhost/database_name --username database_username --password database_password --quiet --eval 'db.Receipts.find({acctId:"100000000001",outlet:"MI MING MART - MK"}).sort({txnTime:-1})' > /dev/null
    real    0m27.904s
    user    0m0.126s
    sys     0m0.026s
    
  • create following compound index can help query for "acctId" AND "outlet" AND "txnType"
    db.Receipts.createIndex({"acctId": 1,"outlet": 1,"txnType": 1,"txnTime": 1})
    $ time mongo mongodb://localhost/database_name --username database_username --password database_password --quiet --eval 'db.Receipts.find({acctId:"100000000001",outlet:"MI MING MART - MK"}).sort({txnTime:-1})' > /dev/null
    real    0m0.277s
    user    0m0.103s
    sys     0m0.033s
    
  • drop redundant indexes
    db.Receipts.dropIndex("acctId_1")
    

Knowledge Base

TLDR

  • compound index increase compound query dramatically from >25s to <1s for 857488 records

mongodb-seed's People

Contributors

chingkamhing avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.