Comments (13)
Can you get me some samples during the high CPU usage, please? That's about the only thing we have to diagnose this.
from connectionkit.
Here are some captures by Instruments (I'm self-taught, so if that isn't what you mean by 'samples,' please correct me). One is a dispatch profile, and the other is a system trace. The code I used was about as basic as it gets - essentially a blank xcode project, and in the appdelegate (in applicationDidFinishLaunching) I get the contents of a directory on an ftp server and then upload a small jpg.
Dispatch - http://bit.ly/10X22PC
System profile - http://bit.ly/14f4O70
The system profile is pretty big (29 mb compressed, 650 mb uncompressed), and Instruments chokes a little to open it, but I think it at least shows that there is something strange going on with dispatching.
If you need anything else, I'd be more than happy to provide it.
from connectionkit.
After some more testing, the cpu load only spikes when using ftp (as opposed to sftp; havne't tested other protocols).
So when I do any kind of operation (get contents of directory, upload a file, etc.) with ftp, the problem occurs. But when I use identical code while switching everything to sftp, the problem disappears.
Unfortunately, I don't know the internals of ConnectionKit very well, but this distinction seems important. I'll hopefully get some time today to dive into it to see if there is any obvious problem, but I wouldn't bet on my skills.
from connectionkit.
Hi, sorry it's taken me a while to get back to this. Those instruments are appreciated, but what would be best for me right now is the simple Time Profiler one, if that's OK with you.
from connectionkit.
No worries at all. Here is the time profile: http://bit.ly/11FHGuo
from connectionkit.
Forgot to mention, here is the code that generated that profile (it's about as simple as it gets, because I was just testing something out):
NSURL *destinationFile = [NSURL URLWithString:@"**Redacted**"];
NSURL *file = [NSURL URLWithString:**Redacted**];
NSData *fileData = [NSData dataWithContentsOfURL:file];
CK2FileManager *fileManager = [[CK2FileManager alloc] init];
[fileManager setDelegate:(id)self];
[fileManager createFileAtURL:destinationFile contents:fileData withIntermediateDirectories:YES openingAttributes:nil progressBlock:^(NSUInteger bytesWritten, NSUInteger previousAttemptCount){
NSLog(@"bytes - %li", (unsigned long)bytesWritten);
}completionHandler:^(NSError *error){
if(error != nil){
NSLog(@"error - %@",[error localizedDescription]);
}
}];
With the delegate method here:
- (void)fileManager:(CK2FileManager *)manager didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge{
NSURLCredential* credential;
credential = [NSURLCredential credentialWithUser:**Redacted**
password:**Redacted**
persistence:NSURLCredentialPersistenceNone];
[challenge.sender useCredential:credential forAuthenticationChallenge:challenge];
}
from connectionkit.
Think I'm starting to get a handle on this. libcurl hands us a timeout value which we're supposed to use for calling back into the library if no other events happen in that time. We schedule that timer with code like this:
dispatch_source_set_timer(timer, DISPATCH_TIME_NOW, self.timeout, self.timeout / 100);
Unfortunately, it looks like that DISPATCH_TIME_NOW
setting is wrong, as it effectively tells GCD "call the timer immediately and then repeat at my timeout rate. This is actually part of the timer's event handler, so the timer is firing pretty much all the time! (and using lots of CPU in the process)
Time (ahem) then, to call in @samdeane. I think we want to readjust our code to be more along the lines of:
dispatch_source_set_timer(timer, dispatch_time(DISPATCH_TIME_NOW, self.timeout), self.timeout, self.timeout / 100);
so that the timer won't fire until self.timeout
has elapsed. Sam, does that seem right to you? Perhaps we don't even want to make the timer repeat? In which case we should pass DISPATCH_TIME_FOREVER
as the interval
from connectionkit.
Interesting. Is that why I see the nsurlconnectionloader thread persisting for no apparent reason after the ftp transaction is complete?
from connectionkit.
No, NSURLConnection
's private thread is permanent and never dies. CK's FTP functionality does not use NSURLConnection
anyway
from connectionkit.
Oh, ok. My bad. I'm pretty new to some of this stuff.
from connectionkit.
@ewrobinson Alright, give the latest v2.x-beta
branch a go (make sure to update submodules too!). Should resolve the CPU issue.
from connectionkit.
After some prelim testing, it looks like the changes work perfectly. Thanks so much for the help!
from connectionkit.
Excellent!
from connectionkit.
Related Issues (20)
- Updating look of CK2OpenPanel for 10.10+
- Support file download HOT 1
- Open Panel error-handling HOT 2
- Authentication HOT 3
- New Folder button shouldn’t be enabled until actually connected HOT 12
- Support uploading of directories using CK2FileManager
- Optimise dequeuing FTP operations
- private ssh key authentication on sftp HOT 2
- Down/Upload and a Crash in Release Build HOT 3
- Add cocoapod HOT 2
- -[CK2OpenPanelController pathControlItemSelected:] exception HOT 4
- CK2FileManager's -enumerateContentsOfURL... sometimes doles out URLs without the username
- -createFileAtURL:... with intermediate directories set to YES doesn't seem to work? HOT 13
- Open panel kicks off a directory listing when being cancelled HOT 6
- Is anyone using -[CK2FileManager setAttributes:…] in their code? HOT 2
- Receiving URL of form https://@dav.box.com/dav HOT 17
- Support for FTP using SSL in Swift 3? HOT 5
- NSURLErrorDomain error -1012 on Sierra? HOT 1
- Incorporate CurlHandle fix 82d036fa7e453b71a01a8a6ba2d7e31560490009
- libcurl broken on 10.12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from connectionkit.