Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify target thread for MPWURLFetchStream #7

Closed
wants to merge 2 commits into from

Conversation

mkarp
Copy link
Contributor

@mkarp mkarp commented Oct 24, 2017

MPWURLFetchStream would always call its targets (including the error target) on whichever threads the underlaying NSURLSession is running on.

This caused thread locking issues in the coalescing while-loop in -executeRequest: method: if a request is scheduled on the same thread that NSURLSession is running on, this thread would sleep, and so the NSURLSession would not be able to complete its request, and so the while-loop will run for a significant time (I've seen up to 25 seconds).

This pull request offers a solution to this problem.

Copy link
Owner

@mpw mpw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea, three notes:

  1. There's already an NSOperationQueue

I don't remember exactly, but I think that one of the last changes I made was to initialize the NBSURLSession in XOBackend, and this NSURLSession is initialized with an NSOperationQueue. My understanding of this parameter to the NSURLSession is that the task-completion blocks are executed on this queue. So the subsequent processing should already be concurrent. If it's not concurrent enough, it should be easy to increase the concurrency parameter in where the NSOperationQueue is initialized (I think in XOBackend).

  1. MPWThreadSwitchStream

If the NSOperationQueue is not sufficient or appropriate, I would simple add an MPWThreadSwitchStream when constructing the pipes. The idea of filters is that they do one thing well.

  1. HOM

If neither the ThreadSwitchStream nor the NSOperationQueue suffice, I'd at least use the HOM:

[[target onThread:self.targetThread] writeObject:processed];

But that would be last resort.

@mpw mpw closed this Jan 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants