Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Timeout for AFNetworking

I'm using AFJSONRequestOperation to upload the images.

In the case of uploading numbers of images, some requests are failed with the timeout error.

I tried

AFJSONRequestOperation *operation = ...
[operation start];

and

AFJSONRequestOperation *operation = ...
[operations addObject:operation];
...
[client enqueueBatchOfHTTPRequestOperations:operations progressBlock:nil completionBlock:nil];

However, still no luck.

I think that the time count starts when the operation is created.

So, should I schedule the requests one by one for my own algorithm?

like image 338
Yun Avatar asked Nov 13 '22 11:11

Yun


1 Answers

Something interesting to note is that AFNetworking will create as many NSOperations as the system has resources for and run them concurrently. The problem is that there are only so many simultaneous network connections the app/computer can make. The count starts as soon as the operation starts. For all practical purposes, on the iPhone you may not see issues since there is less resources to run multiple operations, but the simulator can run hundreds of threads at a time (many more than the max concurrent network connections).

My suggestion is to limit the number of concurrent operations (located in AFHTTPClient I think) to something more reasonable than NSOperationQueueDefaultMaxConcurrentOperationCount which allows the device to run as many as it has resources for.

like image 148
Patrick Hernandez Avatar answered Dec 13 '22 02:12

Patrick Hernandez