Question

I am seeing an issue with RestKit where an outstanding remote request will cause other requests to queue up and block until the previous one completes. I have read that RestKit defaults AFNetworking's setMaxConcurrentOperationCount value to 5, but I am encountering blocking with just a single outstanding request.

Does the current version of RestKit still default this to 5, and if so, what could be causing my lack of concurrent requests?

RestKit 0.20.3

Request

- (RKManagedObjectRequestOperation*) getUser {
    RKObjectManager *objectManager = [RKObjectManager sharedManager];
    NSDictionary *items = [objectManager.HTTPClient defaultHeaders];
    NSString *auth = [items objectForKey:@"Authorization"];

    if (auth == nil) {
        NSLog(@"You must login first\n");
        return nil;
    }

    auth = [auth stringByReplacingOccurrencesOfString:@"Bearer " withString:@""];

    NSMutableString *path = [NSMutableString stringWithFormat:@"/users?accessToken=%@", auth];
    return [[RKObjectManager sharedManager] appropriateObjectRequestOperationWithObject:nil method:RKRequestMethodGET path:path parameters:nil];
}

- (void) getUser:(void ( ^ ) ( RKObjectRequestOperation *operation , RKMappingResult *mappingResult ))success failure:(void ( ^ ) ( RKObjectRequestOperation *operation , NSError *error ))failure {
    RKManagedObjectRequestOperation *requestOperation = [self getUser];
    [requestOperation setCompletionBlockWithSuccess:success failure:failure];

    [requestOperation start];
}

The former is a helper used in testing, and the latter is actually called by Production code. I don't see any place in my code where the Queue size is set explicitly.

Was it helpful?

Solution

RKObjectRequestOperation contains an internal queue (responseMappingQueue) which is shared amongst all instances. This queue is explicitly set with a concurrency count of 1, but it's just used for mapping, not for the URL connections.

Looking at what you're doing, calling start on the operation directly, you most likely want to think about adding the operation to a queue so that you can manage them better. Because you aren't using the object manager to run the operations the concurrent count of 5 that you refer to doesn't apply. Look at using enqueueObjectRequestOperation: to run the operations.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top