ERPNext is very Slow After migrating to AWS

Hi,
I am currently using ERPNext: v12.14.0 (version-12). My current database size is around 12.71 GB. As users complain it takes long to browse ERPNext we decided to migrate the database to AWS. And results become even more worst. And we were rolled back again.

In local server it took only 2.528 seconds to insert a deliveryNote.

In [2]: frappe.get_all(‘Delivery Note’,limit = 1)
Out[2]: [{‘name’: ‘MAT-DN-2021-164174’}]

In [3]: st = frappe.get_doc(‘Delivery Note’ , ‘MAT-DN-2021-164174’)

In [4]: st1 = frappe.copy_doc(st)

In [5]: %prun st1.insert()
1358442 function calls (1277926 primitive calls) in 2.528 seconds

Ordered by: internal time

ncalls tottime percall cumtime percall filename:lineno(function)
668 1.683 0.003 1.683 0.003 {method ‘recv_into’ of ‘_socket.socket’ objects}
13220 0.035 0.000 1.936 0.000 connections.py:648(_read_packet)
55264 0.031 0.000 0.098 0.000 protocol.py:168(read_length_coded_string)
53819 0.028 0.000 0.033 0.000 protocol.py:63(read)
26440 0.026 0.000 1.750 0.000 connections.py:687(_read_bytes)
7698 0.025 0.000 0.128 0.000 protocol.py:237(_parse_field_descriptor)
354 0.025 0.000 0.065 0.000 base_document.py:207(get_valid_dict)
78768/6780 0.024 0.000 0.143 0.000 base_document.py:133(set)

In AWS server it took 19.194 seconds

1358442 function calls (1277926 primitive calls) in 19.194 seconds

Ordered by: internal time

ncalls tottime percall cumtime percall filename:lineno(function)
565 18.171 0.032 18.171 0.032 {method ‘recv_into’ of ‘_socket.socket’ objects}
25073 0.062 0.000 18.483 0.001 connections.py:648(_read_packet)
55264 0.031 0.000 0.098 0.000 protocol.py:168(read_length_coded_string)
53819 0.028 0.000 0.033 0.000 protocol.py:63(read)
26440 0.026 0.000 1.750 0.000 connections.py:687(_read_bytes)
7698 0.025 0.000 0.128 0.000 protocol.py:237(_parse_field_descriptor)
354 0.025 0.000 0.065 0.000 base_document.py:207(get_valid_dict)
78768/6780 0.024 0.000 0.143 0.000 base_document.py:133(set)

What will be the case ?

Check HTOP. Its most probably mySQL hogging the memory. If cloud server is far from your location then it will take more time. Local server in reality works fast if it is within your local area network.

Check gunicorn workers as well.

Is the AWS instance on par with your local server cpu/ram/drive? Is the network speed reasonable?