I'm using OkHttp 3.9 to make a POST call in an Android app to update an AWS DynamoDb database by triggering a Lambda function via an Api Gateway. I notice that the database is updated 3 times with each call. Apparently this is due to the default retry option for OkHttp.
As I understand it, the retries can be prevented by setting retryOnConnectionFailure to false when building the client.I tried this but still the database is updated 3 times - so the call is still being made 3 times.
Some suggest to handle this behaviour on my server. The problem is that if I handle the issue in the Lambda function, then it means that the api has been called three times and so has the lambda function, all unecessary overhead and cost. Also, if setting retryOnConnectionFailure to false worked and the api was only called once, it means that there is no mechanism to handle failure.
So, why does it retry 3 times even when each call succeeds? and most importantly, how do I stop this from happening so that the api is only called once and then again only if the call failed (i.e to succeed in triggering the lambda function)? Setting retryOnConnectionFailure to false seems to have no effect.
So I have egg on my face!
There was no problem with OkHttp! After some further investigation I found a call to update the database in the lambda function that I was calling. So this was calling the extra updates and not OkHttp retries!
sorry.
Related
What I am trying to do: I want to develop REST APIs on AWS to use in my Android application. The purpose of this REST APIs is to call some other REST APIs, get and process data and send back as response.
What I tried: I followed this AWS tutorial Using AWS Lambda as Mobile Application Backend (Custom Event Source: Android). Everything works as expected but the first time response from AWS is too slow. It is something like ~8 secs. However, next time onwards, in the same session, it is responding in 1 to 2 secs.
That may be because it takes a long time in setting up connection and invoking my function at Lambda.
Question: Is there any alternative to this? I want to get the quick response every time, including the first time. Am I trying the right thing (AWS-Lambda) or should I try something else?
Increasing the memory size in the lambda configuration. It usually makes it run in a computer with more CPU power, making it slightly faster. However in your case it seems most of the delay is because the function goes "cold" and aws no longer has it in memory.
There are a few things you can try:
-> Reduce the size of your package so it loads faster, the first invocation will still be slow, but you might improve by a few seconds.
-> Create another dummy CRON type lambda function that triggers your real lambda every minute or so and makes a dummy request, this should help keep your function in memory. You can learn how to create a lambda cron function (aka lambda scheduled task) here: AWS Lambda Scheduled Tasks
I have 21 API calls that need to be made once the app gets to the splash screen. What my app does is as follows:
a> Make API call using retrofit's enqueue method.
b> once the response is available(call success) it stores data to local database using greendao. Inside app it only uses data from greendao databases. What I need is to keep track of the api call whether it failed or not. If failed retry. Also if there is a way to chain the requests can anyone mention them? I looked into rxjava which allows chaining upto 2 or 3 apis (as far as I know). Any help is much appreciated.
You can create IntentService which will run call.execute() code one by one.
This way you will call synchronous call to all apis.
Once all request completes send broadcast to activity or communicate with activity through other mechanism.
I'm having a big performance problem when using AWS Lambda.
I created some basic lambdas that connect to RDS MySQL database and insert/select/delete data in order to return it to the user.
In my client which is an Android App I'm invoking the lambda using aws-android-sdk-lambda:2.2.17 library.
The mismatch is that in the CloudWatch I'm seeing that the Lambdas are being performed really quick - around 60 ms but in my Android app I'm getting the results only after 8-12 seconds.
Unfortunately all that happen after Lambda finishes its invocation and user gets his response is a black box. The problem might be in the implementation of the AWS SDK but I doubt it.
Note - the internet connection is not the problem and it's not a cold execution problem.
Please advice
It seems to work fine but after sometime all calls to saveEventually and saveInBackground are not saving data to parse (there is no callback and there is no error message as well). It seems it is silently discarded. When this happens, we are still able to fetch data from Parse i.e. all read queries work. We are using local storage. The updates start working again once we clear the app data. What could be causing this? How can we debug the requests that are silently discarded?
You are using a synchronous function saveInBackground. If you want to have callbacks, you need to call the asynchronous version saveInBackgroundWithBlock instead.
Please read the Parse documentation carefully before posting a question here.
I am triggering a sync with a REST service using SwipeRefreshLayout's onRefresh method by calling ContentResolver.requestSync, which launches my Syncadapter.
The Syncadapter then uses Volley's Request to communicate with the server.
To detect the end of the sync operation and close the activity indicator I use ContentResolver.isSyncActive inside SyncStatusObserver of the Fragment from which I initiated the sync.
The problem is that the ContentResolver.isSyncActive returns false before the actual sync with the server is over, causing the activity indicator to disappear almost immediately.
Am I correct assuming that the asynchronous nature of Volley's Request causes the SyncAdapter's onPerformSync to return immediately which, in turn, makes the ContentResolver think that the sync is over?
If yes, what is the correct/recommended solution here? I can come up with workarounds, but wanted to make sure I am not missing something obvious.
I have looked through many examples including iosched, swiperefresh, basicsyncadapter etc., but they all seem to "hold" the onPerformSync method until everything is over.
Thank you
You should make the requests act synchronously inside the onPerformSync method. I use Retrofit for calls with backends but I think Volley should also provide the synchronous functionality.