-1

What's the most optimized way to run MongoDB in AWS? I'm getting some slow disk i/o bench marks (which I understand is the norm on EC2). Is a large ec2 instance my best bet? is there anyway to get better disk reads?

imaginative
  • 1,971
  • 10
  • 32
  • 48
  • You're going to need to give us more information about what you're trying to do. – Publiccert Feb 20 '12 at 20:17
  • 3
    MongoDB performs best if the entire database can fit in memory - so a high memory instance may be a consideration, especially if your application is read-heavy (good indexes will also help). Secondly, various instance classes have different 'I/O Performance' - the large instance class has 'high' I/O performance. Finally, You can improve the read/write performance of your EBS volumes by setting them up as a RAID. – cyberx86 Feb 20 '12 at 20:26
  • cyberx86: why not put that in as a solution so I can up vote you? Also, is there a way to force MongoDB store into memory? How can I tell how much is hitting disk and how much is in memory? – imaginative Feb 20 '12 at 20:30

1 Answers1

7

MongoDB performs best if the entire database can fit in memory - so a high memory instance may be a consideration, especially if your application is read-heavy (good indexes will also help).

MongoDB uses memory mapped files - so it is fairly efficient about what it stores in memory and what it writes to disk. Indexes are prioritized, and should always be in memory (the performance implications are significant if the indexes do not fit in memory).

As a general guideline, you should try to minimize indexes on write-heavy applications (since each write requires an additional write for the index). Read-heavy applications should use indexes on whatever fields are commonly accessed.

Secondly, various instance classes have different 'I/O Performance' - the large instance class has 'high' I/O performance.

Finally, You can improve the read/write performance of your EBS volumes by setting them up as a RAID. This is fairly easy to accomplish using mdadm.

You can check disk access using iostat (see how many reads/writes are occurring on a disk). From the MongoDB side of things, use db.serverStatus() in the mongo shell, to get relevant data (e.g. the mem section describes memory usage, while backgroundFlushing describes writes to disk.

For a small read-heavy database residing on the same machine as the application querying it, all instance sizes (except, perhaps t1.micro) that will fit it in memory should be essentially equivalent (since the required I/O is minimal). For write-heavy applications, I/O becomes a much more significant consideration.

cyberx86
  • 20,805
  • 1
  • 62
  • 81