• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 546
  • Last Modified:

Async and Sync HttpWebRequests

Hello Experts,

I am hoping to get a little better understanding about how these requests affect each other.

I have two routines I am using to gather data from the same source.  They are getting exactly the same type of data.  The async request gets a larger amount of data, it does this every 15 secs.  The sync request gets a much smaller set of the same data typically 1/250 the size, it does this as quickly as it is able and averages about 1 sec when there is no async request pending.

When the async request is receiving its data but is not finished yet I notice that the sync request time increases to 3 secs.  Here is an example of the time stamps

req sync 1
rec sync 2
req sync 2
rec sync 3
rec async 3
ack async request 3
req sync 3
rec sync 6
chk async 6 not done
req sync 6
rec sync 9
chk async 9 done
rec async 10
req sync 10
rec sync 11
req sync 11
rec sync 12
...

I am trying to understand what is happening when both streams are being received at the same time.  Is the delay on the sync steam caused because they must be received serially?  Ie a chunk comes in from the async then some comes in from the sync, then more from the async?  The sync request waits as long as is necessary to receive all its packets which are interspersed with the async packets?

Thanks for you comments!
0
Mithrinder
Asked:
Mithrinder
  • 2
  • 2
2 Solutions
 
nehayaCommented:

Maybe it's beacuse of the source performance decrease because of muiltiple requests at the same time.

Asynch is executing in different thread, but since you use one stream they both will try to read. one of them must be beofre the other, so, the second one will wait for information to read..

Regards,
Nehaya
0
 
gregoryyoungCommented:
"Asynch is executing in different thread, but since you use one stream they both will try to read. one of them must be beofre the other, so, the second one will wait for information to read.."

Sync and Async will be using a different stream (each should have its own unique connection) providing you are not dealing with a web server which forces data to be serial this is def not the case.
0
 
MithrinderAuthor Commented:
nehaya - each has a different stream it will only wait when handling the sync stream as shown by the time stamps below it varies depending upon the length of the async request even tho it is always the same data size, I am assuming that is because of changes in server load and general internet conditions.

I can have time stamps like this for one async request                 or  like this for the same size data
req async 1                                                                              req async 1
ack async request 1                                                                  ack async request 1
req sync 1                                                                                req sync 1
rec sync 4                                                                                rec sync 4
chk async 4 not done                                                                chk async 4 not done
req sync 4                                                                               req sync 4
rec sync 6                                                                               rec sync 5
chk async 6 not done                                                               hk async 5 done
req sync 6                                                                              rec async 5
rec sync 7
chk async 7 done
rec async 7

gregoryyoung - You are correct each as it's own stream and unique connection.

What I am trying to understand is how is the data actually received to the steam, are they just individual packets?  Each is packet is received, buffered, and built into a file as they are received?  This would explain the delay on the sync request when processing the async request as async packets are also in the datasteam so it takes longer to receive all the sync packets?  ie the data could look like async packet, async packet, sync packet, async packet, async packet, async packet, sync packet, sync packet, async packet, sync packet.....

What I  desire is the following:

req async 1
ack async1
req sync 1
rec sync 2
chk async 2 not done
req sync 2
rec sync 3
chk async 3 not done
req sync 3
rec sync 4
chk async 4 not done
req sync 4
rec sync 5
chk async 5 not done
req sync 5
rec sync 6
chk async 6 done
rec async 6

I dont think this would be possible for the async right?  Once requested the async stream will continue to send packets until complete right?  Is there a way to do the following?

req async 1
ack async1
get async data for 1 sec
hold async data
req sync 1
rec sync 2
resume getting async data for 1 sec
...repeat until done with async request
0
 
MithrinderAuthor Commented:
Anyone?  Comments on the mechanics of how the data is received?
0
 
gregoryyoungCommented:
There is no way to block your async request while you process a sync request.
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now