Skip to content

too many requests to amazon API #248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
amrnablus opened this issue May 10, 2019 · 3 comments
Open

too many requests to amazon API #248

amrnablus opened this issue May 10, 2019 · 3 comments

Comments

@amrnablus
Copy link

Expected Behavior

A single request (or an appropriate number) should be made

Actual Behavior

A single call to findAll with a limit of 20 is loading the whole data set

Steps to Reproduce the Problem

  1. Create a repo
  2. Create a Bean and map it to whatever table (preferably with a large number of rows)
  3. make a call to findAll with a limit of say 10, and notice how the log shows a large number of requests.

Specifications

  • Spring Data DynamoDB Version: 5.1.0
  • Spring Data Version: 2.0.13.RELEASE
  • AWS SDK Version: 1.11.438
  • Java Version: 1.8.0_181
  • Platform Details: Ubuntu 18.04 LST

I tried to trace the problem and it seems a call to PaginatedScanList#size is causing this, isn't it possible to run two queries, one with count(*) and the actual query to get both the size and the needed data?

@amrnablus
Copy link
Author

I traced the code further and it seems there are two main problems:

  1. in src/main/java/org/socialsignin/spring/data/dynamodb/repository/support/SimpleDynamoDBPagingAndSortingRepository.java there is a call to scan function from the aws sdk which scans the whole table rather than scanning within the requested limit, changing this to scanPage fixes one half of the issue
  2. In src/main/java/org/socialsignin/spring/data/dynamodb/core/DynamoDBTemplate.java#count what actually happens is that the limit limits the number of counted rows (personally i think this is a flow in the amazon sdk), setting the limit to null dramatically drops the number of calls

I would be happy to submit a pull request if everybody is fine with the changes.

@boostchicken
Copy link

Use the Query(limit=blah) annotation.

@boostchicken
Copy link

#239

It's in 5.1.1-SNAPSHOT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants