Re: How can I get a single threaded network call in ObjC on iOS?
Just to come back around on this, I ended up using the dispatch_suspend and dispatch_resume method. I had previously explored that but I moved the suspend and resume closer to the network call to make the whole thing simpler. I tried using dispatch_group_enter and dispatch_group_leave but that did not do the same thing. The idea of a queue of messages to send was something I explored quite a long time ago but I found that it tended to make my code more complex than simpler so I had abandoned that idea. > On Jun 28, 2016, at 11:50 PM, Alex Zavatonewrote: > > Smarter people that we are have already spent the time to figure it out. > Learn the way they did it and profit from their work and experience. > > There is a benefit to learning how to create the wheel. That time is not > now. Learn the wheel that we have. > > > On Jun 28, 2016, at 7:03 PM, Peter Tomaselli wrote: > >> I have not a lot of Cocoa experience here, so I am legitimately asking this >> question, no snark intended: what’s the advantage to building a home-made >> “serial” “queue” as opposed to just using an actual serial operation queue? >> Haven’t you just described the first few steps one would take were one to >> set out to reimplement NSOperationQueue? >> >> FWIW (and as I mentioned, I am an eminently ignorable person when it comes >> to Cocoa expertise), I sort of see the essence of the “async” flavor of >> NSOperation as being to provide definitive signaling when an otherwise >> asynchronous operation is really “finished“ — for whatever business >> definition of “finished” one requires. So I don’t completely agree that this >> would be “shoehorning”; seems right on the money to me. >> >> Just one opinion! Cheers, >> >> Peter >> >> On Jun 28, 2016, at 6:50 PM, "Gary L. Wade" >> wrote: >> >>> Based on his desire to do this serially, he would need a serial queue, and >>> he's using asynchronous requests, so succeeding calls from his completion >>> handler with a simple array in queue pattern is simpler than shoehorning it >>> all into dispatch queues. >>> -- >>> Gary L. Wade (Sent from my iPhone) >>> http://www.garywade.com/ >>> On Jun 28, 2016, at 3:45 PM, Alex Zavatone wrote: Would a dispatch queue get what he's looking for? >> > > > ___ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > Please do not post admin requests or moderator comments to the list. > Contact the moderators at cocoa-dev-admins(at)lists.apple.com > > Help/Unsubscribe/Update your Subscription: > https://lists.apple.com/mailman/options/cocoa-dev/jim.adams%40sas.com > > This email sent to jim.ad...@sas.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: How can I get a single threaded network call in ObjC on iOS?
Smarter people that we are have already spent the time to figure it out. Learn the way they did it and profit from their work and experience. There is a benefit to learning how to create the wheel. That time is not now. Learn the wheel that we have. On Jun 28, 2016, at 7:03 PM, Peter Tomaselli wrote: > I have not a lot of Cocoa experience here, so I am legitimately asking this > question, no snark intended: what’s the advantage to building a home-made > “serial” “queue” as opposed to just using an actual serial operation queue? > Haven’t you just described the first few steps one would take were one to set > out to reimplement NSOperationQueue? > > FWIW (and as I mentioned, I am an eminently ignorable person when it comes to > Cocoa expertise), I sort of see the essence of the “async” flavor of > NSOperation as being to provide definitive signaling when an otherwise > asynchronous operation is really “finished“ — for whatever business > definition of “finished” one requires. So I don’t completely agree that this > would be “shoehorning”; seems right on the money to me. > > Just one opinion! Cheers, > > Peter > > On Jun 28, 2016, at 6:50 PM, "Gary L. Wade"> wrote: > >> Based on his desire to do this serially, he would need a serial queue, and >> he's using asynchronous requests, so succeeding calls from his completion >> handler with a simple array in queue pattern is simpler than shoehorning it >> all into dispatch queues. >> -- >> Gary L. Wade (Sent from my iPhone) >> http://www.garywade.com/ >> >>> On Jun 28, 2016, at 3:45 PM, Alex Zavatone wrote: >>> >>> Would a dispatch queue get what he's looking for? > ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: How can I get a single threaded network call in ObjC on iOS?
When you try to mix synchronous (one request at a time) and asynchronous calls (the task is set up and a completion handler is called after the original set up calls) together like this, you have to start doing lots of extra management across queues. This pattern can apply across other asynchronous APIs. If you have 50 requests to execute, in the worst case, you have 50 requests happening with 1 doing work and 49 blocked. Those 49 blocked requests may hog resources unnecessarily. A different way to do this that avoids all that management is to only start the new request once an existing request has finished. If you have 50 requests to execute, in the worst case, you have 1 request happening with 1 doing work and none blocked. The 49 requests not called yet will not tie up any resources. Based on what I understand to be your requirements, and in a very general way, I would do this (written in email): 1. Create a mutable array 2. Create methods that add requests to the end and remove requests from the beginning of that array with a common lock around those operations. There are many ways to do this lock. An easy one to code in Objective-C is the @synchronized block with the array being the object. 3. Call the locking method to add each request as needed. 4. When a request is added such that it's the first one in the array, set up your asynchronous request for it within the locking method. 5. At the end of the request's completion block (all completion blocks should be the same), call the locking method that removes the first request from the array. If there's another request in the array, set up your asynchronous request on it within the locking method. 6. Repeat 5 till empty. Essentially, if not for the asynchronous completion blocks, this is the same design you would use for synchronous requests except for the placement of the completion block and timing of its execution. When I refer to requests, these can be as simple as some application-defined value and actual NSURL and NSURLSession objects not created until step 4/5. -- Gary L. Wade (Sent from my iPad) http://www.garywade.com/ > On Jun 28, 2016, at 5:03 PM, Peter Tomaselliwrote: > > I have not a lot of Cocoa experience here, so I am legitimately asking this > question, no snark intended: what’s the advantage to building a home-made > “serial” “queue” as opposed to just using an actual serial operation queue? > Haven’t you just described the first few steps one would take were one to set > out to reimplement NSOperationQueue? > > FWIW (and as I mentioned, I am an eminently ignorable person when it comes to > Cocoa expertise), I sort of see the essence of the “async” flavor of > NSOperation as being to provide definitive signaling when an otherwise > asynchronous operation is really “finished“ — for whatever business > definition of “finished” one requires. So I don’t completely agree that this > would be “shoehorning”; seems right on the money to me. > > Just one opinion! Cheers, > > Peter > >> On Jun 28, 2016, at 6:50 PM, "Gary L. Wade" >> wrote: >> >> Based on his desire to do this serially, he would need a serial queue, and >> he's using asynchronous requests, so succeeding calls from his completion >> handler with a simple array in queue pattern is simpler than shoehorning it >> all into dispatch queues. >> -- >> Gary L. Wade (Sent from my iPhone) >> http://www.garywade.com/ >> >>> On Jun 28, 2016, at 3:45 PM, Alex Zavatone wrote: >>> >>> Would a dispatch queue get what he's looking for? > ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: How can I get a single threaded network call in ObjC on iOS?
I have not a lot of Cocoa experience here, so I am legitimately asking this question, no snark intended: what’s the advantage to building a home-made “serial” “queue” as opposed to just using an actual serial operation queue? Haven’t you just described the first few steps one would take were one to set out to reimplement NSOperationQueue? FWIW (and as I mentioned, I am an eminently ignorable person when it comes to Cocoa expertise), I sort of see the essence of the “async” flavor of NSOperation as being to provide definitive signaling when an otherwise asynchronous operation is really “finished“ — for whatever business definition of “finished” one requires. So I don’t completely agree that this would be “shoehorning”; seems right on the money to me. Just one opinion! Cheers, Peter On Jun 28, 2016, at 6:50 PM, "Gary L. Wade"wrote: > Based on his desire to do this serially, he would need a serial queue, and > he's using asynchronous requests, so succeeding calls from his completion > handler with a simple array in queue pattern is simpler than shoehorning it > all into dispatch queues. > -- > Gary L. Wade (Sent from my iPhone) > http://www.garywade.com/ > >> On Jun 28, 2016, at 3:45 PM, Alex Zavatone wrote: >> >> Would a dispatch queue get what he's looking for? ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: How can I get a single threaded network call in ObjC on iOS?
> On 2016 Jun 28, at 13:16, Jim Adamswrote: > > the second request cannot go through until the first request has completed … > with a multi threaded system, I cannot figure out a way to do that. Ideas > appreciated. dispatch_semaphore Documentation is currently here: https://developer.apple.com/library/mac/documentation/General/Conceptual/ConcurrencyProgrammingGuide/OperationQueues/OperationQueues.html#//apple_ref/doc/uid/TP40008091-CH102-SW24 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: How can I get a single threaded network call in ObjC on iOS?
Based on his desire to do this serially, he would need a serial queue, and he's using asynchronous requests, so succeeding calls from his completion handler with a simple array in queue pattern is simpler than shoehorning it all into dispatch queues. -- Gary L. Wade (Sent from my iPhone) http://www.garywade.com/ > On Jun 28, 2016, at 3:45 PM, Alex Zavatonewrote: > > Would a dispatch queue get what he's looking for? > >> On Jun 28, 2016, at 3:11 PM, Gary L. Wade wrote: >> >> The simplest way to do what you're asking is to not send another request >> until your completion handler finishes. >> -- >> Gary L. Wade (Sent from my iPhone) >> http://www.garywade.com/ >> >>> On Jun 28, 2016, at 12:52 PM, Jim Adams wrote: >>> >>> I have an application that has the requirement that the accesses to the >>> server be single threaded, i.e. the second request cannot go through until >>> the first request has completed. I am using NSURLSession and >>> NSURLSessionDataTask. I have set the Maximum Concurrent Host number in the >>> configuration to 1 but I have seen evidence that there are simultaneous >>> requests going up to my servers. >>> >>> Actually I don’t think they are truly simultaneous, just that the >>> completion handler doesn’t finish before the next request goes out. Is >>> there a way to make the next request wait until the completion block is >>> exited? >>> >>> My evidence comes from looking in the server logs. I have 3 servers in AWS >>> behind an ELB. If I am able to get the cookies back from the server before >>> sending the next request then my request will go to the same server that >>> the last request went to. If I don’t wait then then the request goes to a >>> random server. If I watch the logs I can see the requests come in on >>> multiple servers. >> ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: How can I get a single threaded network call in ObjC on iOS?
Would a dispatch queue get what he's looking for? On Jun 28, 2016, at 3:11 PM, Gary L. Wade wrote: > The simplest way to do what you're asking is to not send another request > until your completion handler finishes. > -- > Gary L. Wade (Sent from my iPhone) > http://www.garywade.com/ > >> On Jun 28, 2016, at 12:52 PM, Jim Adamswrote: >> >> I have an application that has the requirement that the accesses to the >> server be single threaded, i.e. the second request cannot go through until >> the first request has completed. I am using NSURLSession and >> NSURLSessionDataTask. I have set the Maximum Concurrent Host number in the >> configuration to 1 but I have seen evidence that there are simultaneous >> requests going up to my servers. >> >> Actually I don’t think they are truly simultaneous, just that the completion >> handler doesn’t finish before the next request goes out. Is there a way to >> make the next request wait until the completion block is exited? >> >> My evidence comes from looking in the server logs. I have 3 servers in AWS >> behind an ELB. If I am able to get the cookies back from the server before >> sending the next request then my request will go to the same server that the >> last request went to. If I don’t wait then then the request goes to a random >> server. If I watch the logs I can see the requests come in on multiple >> servers. >> > > > ___ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > Please do not post admin requests or moderator comments to the list. > Contact the moderators at cocoa-dev-admins(at)lists.apple.com > > Help/Unsubscribe/Update your Subscription: > https://lists.apple.com/mailman/options/cocoa-dev/zav%40mac.com > > This email sent to z...@mac.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: How can I get a single threaded network call in ObjC on iOS?
> On Jun 28, 2016, at 12:52 PM, Jim Adamswrote: > > I have an application that has the requirement that the accesses to the > server be single threaded, i.e. the second request cannot go through until > the first request has completed. That’s pretty unusual. I take it this is a restriction of the server, i.e. that it can only handle one HTTP request at a time from a client? > I am using NSURLSession and NSURLSessionDataTask. I have set the Maximum > Concurrent Host number in the configuration to 1 but I have seen evidence > that there are simultaneous requests going up to my servers. You mean HTTPMaximumConnectionsPerHost? If you set that you’ve limited the number of sockets to one, and HTTP 1.x doesn’t multiplex requests on a socket, so you won’t be sending any simultaneous requests. You might need to turn pipelining off (I think it’s off by default, but better safe than sorry.) > My evidence comes from looking in the server logs. I have 3 servers in AWS > behind an ELB. If I am able to get the cookies back from the server before > sending the next request then my request will go to the same server that the > last request went to. If I don’t wait then then the request goes to a random > server. If I watch the logs I can see the requests come in on multiple > servers. That’s odd. I suggest using a tool like HTTPScoop to watch how the requests are being sent on the client. —Jens ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: How can I get a single threaded network call in ObjC on iOS?
That may work, too, but it sure sounds like an awfully heavy way to do it. -- Gary L. Wade (Sent from my iPhone) http://www.garywade.com/ > On Jun 28, 2016, at 2:16 PM, Peter Tomaselliwrote: > > In the past I’ve used NSOperation for this — wrap each request in an async > NSOperation that only signals completion to its queue when its DataTask > completion handler is complete. Then you can blast a bunch of them at a > serial queue and they will come out serially until they are done. > >> On Tue, Jun 28, 2016 at 4:35 PM, Gary L. Wade >> wrote: >> Try using a mutex on your array of requests, when adding and removing them, >> and only pull a request off the array when you're done with your completion >> handler or when you have nothing in progress such as when you first start. >> -- >> Gary L. Wade (Sent from my iPhone) >> http://www.garywade.com/ >> >> > On Jun 28, 2016, at 1:16 PM, Jim Adams wrote: >> > >> > Unfortunately, with a multi threaded system, I cannot figure out a way to >> > do that. Ideas appreciated. >> > >> > My network calls could come from any thread. I could see putting the >> > request into a queue, but how to I make the completion handler run on that >> > same queue so it remains blocked? >> > >> >> On Jun 28, 2016, at 4:11 PM, Gary L. Wade >> >> wrote: >> >> >> >> The simplest way to do what you're asking is to not send another request >> >> until your completion handler finishes. >> >> -- >> >> Gary L. Wade (Sent from my iPhone) >> >> http://www.garywade.com/ >> >> >> >>> On Jun 28, 2016, at 12:52 PM, Jim Adams wrote: >> >>> >> >>> I have an application that has the requirement that the accesses to the >> >>> server be single threaded, i.e. the second request cannot go through >> >>> until the first request has completed. I am using NSURLSession and >> >>> NSURLSessionDataTask. I have set the Maximum Concurrent Host number in >> >>> the configuration to 1 but I have seen evidence that there are >> >>> simultaneous requests going up to my servers. >> >>> >> >>> Actually I don’t think they are truly simultaneous, just that the >> >>> completion handler doesn’t finish before the next request goes out. Is >> >>> there a way to make the next request wait until the completion block is >> >>> exited? >> >>> >> >>> My evidence comes from looking in the server logs. I have 3 servers in >> >>> AWS behind an ELB. If I am able to get the cookies back from the server >> >>> before sending the next request then my request will go to the same >> >>> server that the last request went to. If I don’t wait then then the >> >>> request goes to a random server. If I watch the logs I can see the >> >>> requests come in on multiple servers. >> > ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: How can I get a single threaded network call in ObjC on iOS?
In the past I’ve used NSOperation for this — wrap each request in an async NSOperation that only signals completion to its queue when its DataTask completion handler is complete. Then you can blast a bunch of them at a serial queue and they will come out serially until they are done. On Tue, Jun 28, 2016 at 4:35 PM, Gary L. Wadewrote: > Try using a mutex on your array of requests, when adding and removing > them, and only pull a request off the array when you're done with your > completion handler or when you have nothing in progress such as when you > first start. > -- > Gary L. Wade (Sent from my iPhone) > http://www.garywade.com/ > > > On Jun 28, 2016, at 1:16 PM, Jim Adams wrote: > > > > Unfortunately, with a multi threaded system, I cannot figure out a way > to do that. Ideas appreciated. > > > > My network calls could come from any thread. I could see putting the > request into a queue, but how to I make the completion handler run on that > same queue so it remains blocked? > > > >> On Jun 28, 2016, at 4:11 PM, Gary L. Wade > wrote: > >> > >> The simplest way to do what you're asking is to not send another > request until your completion handler finishes. > >> -- > >> Gary L. Wade (Sent from my iPhone) > >> http://www.garywade.com/ > >> > >>> On Jun 28, 2016, at 12:52 PM, Jim Adams wrote: > >>> > >>> I have an application that has the requirement that the accesses to > the server be single threaded, i.e. the second request cannot go through > until the first request has completed. I am using NSURLSession and > NSURLSessionDataTask. I have set the Maximum Concurrent Host number in the > configuration to 1 but I have seen evidence that there are simultaneous > requests going up to my servers. > >>> > >>> Actually I don’t think they are truly simultaneous, just that the > completion handler doesn’t finish before the next request goes out. Is > there a way to make the next request wait until the completion block is > exited? > >>> > >>> My evidence comes from looking in the server logs. I have 3 servers in > AWS behind an ELB. If I am able to get the cookies back from the server > before sending the next request then my request will go to the same server > that the last request went to. If I don’t wait then then the request goes > to a random server. If I watch the logs I can see the requests come in on > multiple servers. > > > > > ___ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > Please do not post admin requests or moderator comments to the list. > Contact the moderators at cocoa-dev-admins(at)lists.apple.com > > Help/Unsubscribe/Update your Subscription: > https://lists.apple.com/mailman/options/cocoa-dev/vast.grapes%40gmail.com > > This email sent to vast.gra...@gmail.com > ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: How can I get a single threaded network call in ObjC on iOS?
Try using a mutex on your array of requests, when adding and removing them, and only pull a request off the array when you're done with your completion handler or when you have nothing in progress such as when you first start. -- Gary L. Wade (Sent from my iPhone) http://www.garywade.com/ > On Jun 28, 2016, at 1:16 PM, Jim Adamswrote: > > Unfortunately, with a multi threaded system, I cannot figure out a way to do > that. Ideas appreciated. > > My network calls could come from any thread. I could see putting the request > into a queue, but how to I make the completion handler run on that same queue > so it remains blocked? > >> On Jun 28, 2016, at 4:11 PM, Gary L. Wade >> wrote: >> >> The simplest way to do what you're asking is to not send another request >> until your completion handler finishes. >> -- >> Gary L. Wade (Sent from my iPhone) >> http://www.garywade.com/ >> >>> On Jun 28, 2016, at 12:52 PM, Jim Adams wrote: >>> >>> I have an application that has the requirement that the accesses to the >>> server be single threaded, i.e. the second request cannot go through until >>> the first request has completed. I am using NSURLSession and >>> NSURLSessionDataTask. I have set the Maximum Concurrent Host number in the >>> configuration to 1 but I have seen evidence that there are simultaneous >>> requests going up to my servers. >>> >>> Actually I don’t think they are truly simultaneous, just that the >>> completion handler doesn’t finish before the next request goes out. Is >>> there a way to make the next request wait until the completion block is >>> exited? >>> >>> My evidence comes from looking in the server logs. I have 3 servers in AWS >>> behind an ELB. If I am able to get the cookies back from the server before >>> sending the next request then my request will go to the same server that >>> the last request went to. If I don’t wait then then the request goes to a >>> random server. If I watch the logs I can see the requests come in on >>> multiple servers. > ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: How can I get a single threaded network call in ObjC on iOS?
I agree with Gary, but if something about your structure makes that difficult, there’s also a queue suspend/resume approach: let queue = dispatch_queue_create("", DISPATCH_QUEUE_SERIAL) dispatch_async(queue) { dispatch_suspend(queue) myFirstNetworkCall({ (let result) in dispatch_resume(queue) }) } dispatch_async(queue) { dispatch_suspend(queue) mySecondNetworkCall({ (let result) in dispatch_resume(queue) }) } Dan On Jun 28, 2016, at 1:11 PM, Gary L. Wade> wrote: The simplest way to do what you're asking is to not send another request until your completion handler finishes. -- Gary L. Wade (Sent from my iPhone) http://www.garywade.com/ On Jun 28, 2016, at 12:52 PM, Jim Adams wrote: I have an application that has the requirement that the accesses to the server be single threaded, i.e. the second request cannot go through until the first request has completed. I am using NSURLSession and NSURLSessionDataTask. I have set the Maximum Concurrent Host number in the configuration to 1 but I have seen evidence that there are simultaneous requests going up to my servers. Actually I don’t think they are truly simultaneous, just that the completion handler doesn’t finish before the next request goes out. Is there a way to make the next request wait until the completion block is exited? My evidence comes from looking in the server logs. I have 3 servers in AWS behind an ELB. If I am able to get the cookies back from the server before sending the next request then my request will go to the same server that the last request went to. If I don’t wait then then the request goes to a random server. If I watch the logs I can see the requests come in on multiple servers. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/dstenmark%40opentable.com This email sent to dstenm...@opentable.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: How can I get a single threaded network call in ObjC on iOS?
Unfortunately, with a multi threaded system, I cannot figure out a way to do that. Ideas appreciated. My network calls could come from any thread. I could see putting the request into a queue, but how to I make the completion handler run on that same queue so it remains blocked? > On Jun 28, 2016, at 4:11 PM, Gary L. Wade> wrote: > > The simplest way to do what you're asking is to not send another request > until your completion handler finishes. > -- > Gary L. Wade (Sent from my iPhone) > http://www.garywade.com/ > >> On Jun 28, 2016, at 12:52 PM, Jim Adams wrote: >> >> I have an application that has the requirement that the accesses to the >> server be single threaded, i.e. the second request cannot go through until >> the first request has completed. I am using NSURLSession and >> NSURLSessionDataTask. I have set the Maximum Concurrent Host number in the >> configuration to 1 but I have seen evidence that there are simultaneous >> requests going up to my servers. >> >> Actually I don’t think they are truly simultaneous, just that the completion >> handler doesn’t finish before the next request goes out. Is there a way to >> make the next request wait until the completion block is exited? >> >> My evidence comes from looking in the server logs. I have 3 servers in AWS >> behind an ELB. If I am able to get the cookies back from the server before >> sending the next request then my request will go to the same server that the >> last request went to. If I don’t wait then then the request goes to a random >> server. If I watch the logs I can see the requests come in on multiple >> servers. >> > ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: How can I get a single threaded network call in ObjC on iOS?
The simplest way to do what you're asking is to not send another request until your completion handler finishes. -- Gary L. Wade (Sent from my iPhone) http://www.garywade.com/ > On Jun 28, 2016, at 12:52 PM, Jim Adamswrote: > > I have an application that has the requirement that the accesses to the > server be single threaded, i.e. the second request cannot go through until > the first request has completed. I am using NSURLSession and > NSURLSessionDataTask. I have set the Maximum Concurrent Host number in the > configuration to 1 but I have seen evidence that there are simultaneous > requests going up to my servers. > > Actually I don’t think they are truly simultaneous, just that the completion > handler doesn’t finish before the next request goes out. Is there a way to > make the next request wait until the completion block is exited? > > My evidence comes from looking in the server logs. I have 3 servers in AWS > behind an ELB. If I am able to get the cookies back from the server before > sending the next request then my request will go to the same server that the > last request went to. If I don’t wait then then the request goes to a random > server. If I watch the logs I can see the requests come in on multiple > servers. > ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
How can I get a single threaded network call in ObjC on iOS?
I have an application that has the requirement that the accesses to the server be single threaded, i.e. the second request cannot go through until the first request has completed. I am using NSURLSession and NSURLSessionDataTask. I have set the Maximum Concurrent Host number in the configuration to 1 but I have seen evidence that there are simultaneous requests going up to my servers. Actually I don’t think they are truly simultaneous, just that the completion handler doesn’t finish before the next request goes out. Is there a way to make the next request wait until the completion block is exited? My evidence comes from looking in the server logs. I have 3 servers in AWS behind an ELB. If I am able to get the cookies back from the server before sending the next request then my request will go to the same server that the last request went to. If I don’t wait then then the request goes to a random server. If I watch the logs I can see the requests come in on multiple servers. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com