Expand my Community achievements bar.

required to show a data of an id from an csv file from dam

Avatar

Level 2

For a requirement on which data needs to be displyed from the csv file (this may be updated at times) from dam folder on searching of ID from Which is having a14k records. Triggering a servlet on search and putting records into a Map and displaying it by below idMap.containsKey(id) and giving the response back. As if the request are getting more the server is getting high cpu. Any solution can be applied in this scenario. 

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

7 Replies

Avatar

Level 7

Hi @sudeepKonjeti ,

Is the csv file stored in AEM DAM and has around 14k rows, on which you are iterating to fetch a certain ID ?

Regards,

Anupam Patra

Avatar

Level 2

Hi @anupampat  yes its is dam folder. 

Avatar

Community Advisor

Hi @sudeepKonjeti ,

As the number of requests increases, high CPU usage occurs due to repeated file parsing and object creation. You can follow the approach below to optimize access, improve scalability, and ensure fast responses.

1. Use In-Memory Cache (Guava Cache)

  • Store CSV data in memory and fetch IDs efficiently.
  • Avoids repeated file reading on each request.

2. Implement Read-Write Lock

  • Prevents multiple concurrent cache updates.

3. Use AEM Sling Scheduler for Cache Refresh

  • Auto-refresh cache every 30 minutes in the background.

Regards,

Shiv Prakash

HI @Shiv_Prakash_Patel  thanks for your suggestion.  But I can see the users are unique so every time new ID may be fetched in that case how much feasible this approach.  

Avatar

Level 7

To optimize performance and reduce CPU usage:

Use In-Memory Cache (e.g., Guava Cache) to store parsed CSV data, avoiding repeated file parsing on each request.
Implement Read-Write Lock to prevent concurrent cache updates.
Use AEM Sling Scheduler to automatically refresh the cache every 30 minutes or as needed.

This approach improves scalability and ensures faster responses.

Avatar

Level 4

Hi @sudeepKonjeti 

 

there are three ways that you can use:

 

  1. Resource based servlet with a selector - having id as a selector will have a separate cache for individual requests if the data is not getting updated runtime. you can set the cache ttl accordingly to have the updated content.
  2. Memory based cache - Guava Cache(https://www.baeldung.com/guava-cache) - It's a great feature that you can use to have memory-based cache with a lot of customizations.
  3. ACS Commons HTTP Cache (https://adobe-consulting-services.github.io/acs-aem-commons/features/http-cache/index.html) - this is similar to Guava cache but instead of storing some particular java object, it stores the complete request and you can define the TTL for this.

Avatar

Administrator

@sudeepKonjeti Did you find the suggestions helpful? Please let us know if you need more information. If a response worked, kindly mark it as correct for posterity; alternatively, if you found a solution yourself, we’d appreciate it if you could share it with the community. Thank you!



Kautuk Sahni