BroBan
BroBan

Reputation: 172

nodejs & Mongo application performance problems on AWS

Hello people of stack overflow,

I have recently deployed my node application on AWS by using bitnami provided MEAN solution to set up the environment and this is my first application deployed here.

One of the applications functionality is to query mongodb (~20k records) and then do some analysis on each record looping the array that this record contains (approximately 30 objects in the array).

I hope you get the idea of the relative intensity in resources for this operation and so now here comes the problem that doesn't let me sleep at night:

This whole process takes around 27 seconds on my own machine (i5 3.4ghz cpu, 16gb ram, Samsung 840 evo SSD, linux mint OS) but when i run it on a AWS instance (i'm currently using t2.small, but i tried running this same operation using one of the largest instances available with ridiculous amount of resources yielding the same result) the process takes around 90 seconds. The query alone to filter and retrieve the 20k objects takes around 30 seconds on AWS, whereas on my machine it under 9 seconds. When looking at the resources while this is running i can see that the CPU is not at a 100%, so the cpu is not a bottleneck (My CPU credits are constantly near the maximum). Adding more ram by changing to a huge instance also did not help...

It's not like my machine is very powerful or anything, but the performance difference is unbelievable and this makes that particular functionality unusable on AWS.

I have also tried changing my AWS volume to IOPS but with no luck..

Please the experts of this forum - help me with this huge headache of a problem...

Upvotes: 1

Views: 480

Answers (2)

Adiii
Adiii

Reputation: 59946

Choose the right instance with right size.I have experience t2.small it's take long time under heavy load.

You did not explain in your question so base of own experience with AWS i will recommend you to

Check free Space of RAM in your instance

CPU usage

Harddisk space

To avoid these issue see the recommendation of MongoDB portal

Before you host on AWS you must understand the AWS Architecture Something that effect performance

  • Instance Size (Memory and CPU)

Size is everything - choose the right instance type

Based on our experience helping to implement and support MongoDB deployments on AWS, we have found that the M4, I2, and R3 Amazon ECW instance types tend to be the most successful and widely used in customer deployments.

  • Storage/Disk

EBS is the general type of storage that we recommend for EC2 for MongoDB and we’ll dive into how best to configure it. When choosing your disks we have to ask AWS to guarantee our Input/Output Operations Per Second (IOPS) by requesting Provisioned IOPS (PIOPS).

  • Networking

    Because MongoDB can benefit from high packet-per-second performance and lower inter-instance latency networking, Amazon’s Enhanced Networking feature can provide significantly improved performance and consistency. If your instance type supports the Enhanced Networking feature, we strongly recommend that you enable it.

For more detail Maximizing MongoDB Performance on AWS

Upvotes: 1

Ben Fellows
Ben Fellows

Reputation: 59

I don't know if you have checked your NodeJS code for configuration issues. E.g is there some background connection to another database failing and delaying the response? Are there any other services the app is trying to connect to e.g an external mail service etc... Anything that requires connectivity to anything else in AWS requires correct VPC/Routing configuration, I'm not saying this is the issue, but just covering all bases.

Upvotes: 0

Related Questions