big xml multithreading loading and parsing



i'm trying to download and parse big xml file, and using for this libxml, so i'm looking for a apple example called LibXMLParser and my problem is that cpu always 110% and on 120k objects is faults.



[NSThread detachNewThreadSelector:@selector(downloadAndParse:) toTarget:self withObject:url];

- (void)downloadAndParse:(NSURL *)url {

self.characterBuffer = [NSMutableData data];
NSURLRequest *theRequest = [NSURLRequest requestWithURL:url];
self.connection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
context = xmlCreatePushParserCtxt(&simpleSAXHandlerStruct, (__bridge void *)(self), NULL, 0, NULL);
if (self.connection != nil) {
do {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
} while (!self.done);
}
// Release resources used only in this thread.
xmlFreeParserCtxt(context);
self.characterBuffer = nil;
self.parseFormatter = nil;
self.connection = nil;
self.currentItem = nil;
}


loading a made with this way:



- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
xmlParseChunk(context, (const char *)[data bytes], [data length], 0);
}

2014-08-05 02:35:42.130 Zarubin[13257:3503] *** Assertion failure in void errorEncounteredSAX(void *, const char *, ...)(), /Users/vitaliyzarubin/Documents/Apps/My/TestWork/Zarubin/Zarubin/LibXMLParser.m:250
2014-08-05 02:35:42.132 Zarubin[13257:3503] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Unhandled error encountered during SAX parse.'
*** First throw call stack:
(
0 CoreFoundation 0x0269d1e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x0241c8e5 objc_exception_throw + 44
2 CoreFoundation 0x0269d048 +[NSException raise:format:arguments:] + 136
3 Foundation 0x020c8b20 -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 101
4 Zarubin 0x00007341 errorEncounteredSAX + 225
5 libxml2.2.dylib 0x00f95ed1 __xmlRaiseError + 1279
6 libxml2.2.dylib 0x00faafe4 xmlFatalErr + 341
7 libxml2.2.dylib 0x00fbad4b xmlParseChunk + 967
8 Zarubin 0x000068f9 -[LibXMLParser connection:didReceiveData:] + 201
9 Foundation 0x021e5e80 ___NSURLConnectionDidReceiveData_block_invoke + 50
10 Foundation 0x0217c7e1 __65-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:]_block_invoke + 62
11 Foundation 0x02004f5e -[NSURLConnectionInternalConnection invokeForDelegate:] + 119
12 Foundation 0x02004ec6 -[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] + 208
13 Foundation 0x02004dd8 -[NSURLConnectionInternal _withActiveConnectionAndDelegate:] + 76
14 Foundation 0x02005158 _NSURLConnectionDidReceiveData + 87
15 CFNetwork 0x0032e171 ___ZN27URLConnectionClient_Classic29_delegate_didReceiveDataArrayEv_block_invoke + 304
16 CFNetwork 0x0032d3de ___ZN27URLConnectionClient_Classic18_withDelegateAsyncEPKcU13block_pointerFvP16_CFURLConnectionPK33CFURLConnectionClientCurrent_VMaxE_block_invoke_2 + 104
17 CoreFoundation 0x0263ec69 CFArrayApplyFunction + 57
18 CFNetwork 0x00296441 _ZN19RunloopBlockContext7performEv + 155
19 CFNetwork 0x003783f4 _ZThn16_N19RunloopBlockContext24multiplexerClientPerformEv + 20
20 CFNetwork 0x00296257 _ZN17MultiplexerSource7performEv + 299
21 CFNetwork 0x0029606c _ZN17MultiplexerSource8_performEPv + 76
22 CoreFoundation 0x0262677f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
23 CoreFoundation 0x0262610b __CFRunLoopDoSources0 + 235
24 CoreFoundation 0x026431ae __CFRunLoopRun + 910
25 CoreFoundation 0x026429d3 CFRunLoopRunSpecific + 467
26 CoreFoundation 0x026427eb CFRunLoopRunInMode + 123
27 Foundation 0x02078e35 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 284
28 Zarubin 0x00006706 -[LibXMLParser downloadAndParse:] + 550
29 Foundation 0x02073a07 -[NSThread main] + 76
30 Foundation 0x02073966 __NSThread__main__ + 1275
31 libsystem_pthread.dylib 0x030ff21f _pthread_body + 138
32 libsystem_pthread.dylib 0x030ff195 _pthread_body + 0
33 libsystem_pthread.dylib 0x030fd2fe thread_start + 34
)

No comments:

Post a Comment