Re: REST calling REST

2016-06-21 Thread David Rhys Jones
Hi
I run across this sort of oddity regulaly
I've just started a project to support an existing system, I recently came
across a DB call that was wrapped in an async await call, I found that it
was throwing exceptions 2 /3 of the time.

I removed the async await, and the pallalel foreach to populate the
objects, and all was working correctly and running 2 seconds faster, the
website already calls the service async with ajax.
I'm against using async calls inside server code when accessing outside
resources. If the process is too long then it needs refactoring to simplify
the call.

.02c
Davy



*Si hoc legere scis nimium eruditionis habes*.


On Tue, Jun 21, 2016 at 4:42 AM, Greg Keogh  wrote:

> Are the calls on the same server? If so remove the async await, from the
>> call and try again, did you get an error?
>>
>
> Yesterday I gave up and used a synchronous WebClient.DownloadString inside
> the WebApi controller and it worked fine.
>
> Today as an experiment I rejigged the code a bit. I made the controller
> method async Task and inside it I created two Task using
> await WebRequest Task.Factory.FromAsync(beginxx,endxx). I did a WhenAll on
> the two tasks and they all worked fine.
>
> One call was to localhost where I was debugging and the other to a remote
> server. So today this has disproved my theory (like you had) that debugging
> and calling localhost was a problem. Today it all just works!
>
> It opens up philosophical questions about where in the WebApi call stack
> should the asynchrony start and stop. Web searches find lots of often
> contradictory arguments and advice on this matter.
>
> *GK*
>


RE: REST calling REST

2016-06-21 Thread Adrian Halid
This article may help.

It is very detailed and may have tips on where things have gone wrong.

 

https://msdn.microsoft.com/en-us/magazine/dn802603.aspx

 

 

Regards

 

Adrian Halid 

 

From: ozdotnet-boun...@ozdotnet.com [mailto:ozdotnet-boun...@ozdotnet.com] On 
Behalf Of David Rhys Jones
Sent: Tuesday, 21 June 2016 4:01 PM
To: ozDotNet 
Subject: Re: REST calling REST

 

Hi

I run across this sort of oddity regulaly

I've just started a project to support an existing system, I recently came 
across a DB call that was wrapped in an async await call, I found that it was 
throwing exceptions 2 /3 of the time.

 

I removed the async await, and the pallalel foreach to populate the objects, 
and all was working correctly and running 2 seconds faster, the website already 
calls the service async with ajax.

I'm against using async calls inside server code when accessing outside 
resources. If the process is too long then it needs refactoring to simplify the 
call. 

 

.02c

Davy

 




 

Si hoc legere scis nimium eruditionis habes.

 

 

On Tue, Jun 21, 2016 at 4:42 AM, Greg Keogh mailto:gfke...@gmail.com> > wrote:

Are the calls on the same server? If so remove the async await, from the call 
and try again, did you get an error?

 

Yesterday I gave up and used a synchronous WebClient.DownloadString inside the 
WebApi controller and it worked fine.

 

Today as an experiment I rejigged the code a bit. I made the controller method 
async Task and inside it I created two Task using await 
WebRequest Task.Factory.FromAsync(beginxx,endxx). I did a WhenAll on the two 
tasks and they all worked fine.

 

One call was to localhost where I was debugging and the other to a remote 
server. So today this has disproved my theory (like you had) that debugging and 
calling localhost was a problem. Today it all just works!

 

It opens up philosophical questions about where in the WebApi call stack should 
the asynchrony start and stop. Web searches find lots of often contradictory 
arguments and advice on this matter.

 

GK

 



Re: REST calling REST

2016-06-21 Thread Davy Jones
Hi
I've read that article before, and unless you are working with the very latest 
version of sql server there are some very big pitfalls to avoid.

I know where the code I'm supporting went wrong,  all the calls to the database 
are wrapped in async await, where the database can't cope with the number of 
requests being made (Oracle 10g) 
By moving the async calls to the controllers I've increased the number of 
concurrent connections and the speed of both database and website. 

Davy

Sent from my iPhone

> On 21 Jun 2016, at 13:28, Adrian Halid  wrote:
> 
> This article may help.
> It is very detailed and may have tips on where things have gone wrong.
>  
> https://msdn.microsoft.com/en-us/magazine/dn802603.aspx
>  
>  
> Regards
>  
> Adrian Halid 
>  
> From: ozdotnet-boun...@ozdotnet.com [mailto:ozdotnet-boun...@ozdotnet.com] On 
> Behalf Of David Rhys Jones
> Sent: Tuesday, 21 June 2016 4:01 PM
> To: ozDotNet 
> Subject: Re: REST calling REST
>  
> Hi
> I run across this sort of oddity regulaly
> I've just started a project to support an existing system, I recently came 
> across a DB call that was wrapped in an async await call, I found that it was 
> throwing exceptions 2 /3 of the time.
>  
> I removed the async await, and the pallalel foreach to populate the objects, 
> and all was working correctly and running 2 seconds faster, the website 
> already calls the service async with ajax.
> I'm against using async calls inside server code when accessing outside 
> resources. If the process is too long then it needs refactoring to simplify 
> the call. 
>  
> .02c
> Davy
>  
> 
>  
> Si hoc legere scis nimium eruditionis habes.
>  
>  
> On Tue, Jun 21, 2016 at 4:42 AM, Greg Keogh  wrote:
> Are the calls on the same server? If so remove the async await, from the call 
> and try again, did you get an error?
>  
> Yesterday I gave up and used a synchronous WebClient.DownloadString inside 
> the WebApi controller and it worked fine.
>  
> Today as an experiment I rejigged the code a bit. I made the controller 
> method async Task and inside it I created two Task using 
> await WebRequest Task.Factory.FromAsync(beginxx,endxx). I did a WhenAll on 
> the two tasks and they all worked fine.
>  
> One call was to localhost where I was debugging and the other to a remote 
> server. So today this has disproved my theory (like you had) that debugging 
> and calling localhost was a problem. Today it all just works!
>  
> It opens up philosophical questions about where in the WebApi call stack 
> should the asynchrony start and stop. Web searches find lots of often 
> contradictory arguments and advice on this matter.
>  
> GK
>