Paul Medawar
Posts: 0
Joined: Thu Apr 03, 2014 10:55 am

Calling services at the same time

Hi,

I have an array of 6 values saved to local storage, and want to save each of those values to a separate row in my database.

I've got 6 separate rest services for each indexed item.

Should I call all 6 rest services at the same time.

Or is it better to call the first service, then on service complete, call the next service and so on?

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

Calling services at the same time

Paul, if you're looking for opinions, mixed with some facts ... I prefer the sequential route with the calling of the next service ... tied to the completion event ...

Factually, if there's an issue ... it's harder to debug if the services are executing at the same time ... and , it's hard to see where you are in the call stack if if you're running them simultaneously....

Also ... there's a chance you may reach your burst rate limit if you execute them at the same time ....

There's probably some pros of doing them together ... just can't think of any right now lol.

Best,
Bruce

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Calling services at the same time

Hello Paul,

It is OK to send them at the same time. If you run them one by one - it is a time-consuming process to wait the response from all 6 services

Paul Medawar
Posts: 0
Joined: Thu Apr 03, 2014 10:55 am

Calling services at the same time

Thanks for the info Bruce/Serhii!

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

Calling services at the same time

Serhii,

I have a production issue with a client that designed his app without care as to the number of services he is executing at the same time in Appery.

He's running about 7 services simultaneously to grab PDF's and other data stores with Appery. He's contracted me to fix it ... along with several other design issues his clients have complained about. Specifically... his customers are getting the burst rate error .. and I've seen it in my own apps recently ... even ones that are designed carefully as I've stated above.

Does your response above (a) take this type of error into account and (b) if so ... I'm going to ask you and the team to do a deep dive on my client's issue ... with the understanding that there's likely another bug or issue at the core and not the simultaneous execution path design they've taken ?

Best,
Bruce

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Calling services at the same time

Hello Bruce,

If you want us to help you debug the app, please consider purchasing the Advisory Pack service: http://appery.io/service. his service includes app debugging as well as any other custom app help. If this particular issue turns out to be an Appery.io bug, we will credit back the hours spent on this issue and you will be able to use them toward another issue.

Jeffry Reed
Posts: 0
Joined: Sun Aug 14, 2016 3:59 pm

Calling services at the same time

I concur with Bruce in that uncontrolled API execution can lead to exceeding burst rate limit... it actually doesn't take much, especially if the number of users and when the user invokes the service(s) is unknown.

At a minimum I would use promises with a timer if not waiting for the prior service to complete. You will have a much more predictable user experience. Check out this simple example

codevar firstMethod = function() {
var promise = new Promise(function(resolve, reject){
setTimeout(function() {
console.log('first method completed');
resolve({data: '123'});
}, 2000);
});
return promise;
};

var secondMethod = function(someStuff) {
var promise = new Promise(function(resolve, reject){
setTimeout(function() {
console.log('second method completed');
resolve({newData: someStuff.data + ' some more data'});
}, 2000);
});
return promise;
};

var thirdMethod = function(someStuff) {
var promise = new Promise(function(resolve, reject){
setTimeout(function() {
console.log('third method completed');
resolve({result: someStuff.newData});
}, 3000);
});
return promise;
};

firstMethod()
.then(secondMethod)
.then(thirdMethod);
/code

I could be wrong though.

Return to “Issues”