medusa icon indicating copy to clipboard operation
medusa copied to clipboard

Performance issue with counting in admin order list

Open khanh-to-niteco opened this issue 1 year ago • 4 comments

Bug report

Describe the bug

Hi Medusa team,

We are doing load tests with around 250K orders in the system, we notice that the order list in admin takes quite some time to respond, Through investigation, it seems that the counting when loading the list takes a lot of time, it seems that the DB has to scan the whole table which slows it down over time. The other queries seem to have run fast and scale well after adding indexes.

This is our test environment, in PROD we can expect to handle more data with more processing power but we may have much more data in PROD accumulated over time pretty quick.

image

System information

Medusa version (including plugins): 1.17.4 Node.js version: 18 Database: Postgres Operating system: Linux Browser (if relevant):

khanh-to-niteco avatar Mar 07 '24 08:03 khanh-to-niteco

You might need to add specific indexes for you such as what is displayed here https://github.com/medusajs/medusa/issues/6307 with cluster index etc. We can't cover all needs in terms of indexes and db tuning as it can have bad impact for other cases. So it is a case by case needs

adrien2p avatar Mar 10 '24 17:03 adrien2p

Hi @adrien2p ,

Not sure if indexes can help with count. I added clustered index in the test before. There are some articles pointing out issues with count and suggesting alternatives:

https://www.cybertec-postgresql.com/en/postgresql-count-made-fast/ https://www.citusdata.com/blog/2016/10/12/count-performance/

khanh-to-niteco avatar Mar 11 '24 06:03 khanh-to-niteco

Hi @adrien2p ,

Related to the above issue. It seems that Medusa internally calls listAndCount in the list method for some places. For example:

image

This could cause performance issues in many places using the list method that don't need the count

khanh-to-niteco avatar Mar 12 '24 09:03 khanh-to-niteco