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

High CPU usage #15

Open
iDevo opened this issue Aug 24, 2018 · 0 comments
Open

High CPU usage #15

iDevo opened this issue Aug 24, 2018 · 0 comments

Comments

@iDevo
Copy link

iDevo commented Aug 24, 2018

Hi there!
I'm trying to build an App which pulls a lot of information from a SSH server.

On startup the puller executes a lot of single commands (like 20) almost at once, in order to fetch all relevant information asap from the system. After the start the App pulls further information on a regular basis every 30 seconds 5 commands.
The CPU load rushes up and the App needs almost 2-3 CPU units at the beginning (which is fine for me, regarding the amount of work to do) but the problem is, that the CPU load almost remains this high and goes also up after a little amount of time, when the puller starts pulling every 30 sec.
Without the high amount of commands after startup, the CPU starts with a load of 30% and goes slowly up to 100%, due to the regular pulling. I was expecting a normal CPU load after all commands have finished executing.

Also a maybe related phenomenon is, that sometimes the callback function of the Command object never gets called, also after the timeout is passed a long time ago. This is why I've set a custom timeout in a more abstract method, to be able to get a feedback. This is weird because I can verify that the command is executed on the target system, I'm just not getting the response. This is happening a lot (80%) during the burst of commands during the startup but also sometimes while pulling. Unfortunately I couldn't find a reason or a step-by-step description on how to reproduce the issue, so just FYI.

I know this is an extreme usage of the framework, so this behavior could be normal but my question is, is there a way I can improve my code, so the CPU load decreases after the execution of a command?

All in all I just want to thank you one more time for your awesome work you did here! Great job and it helped me a lot, just wanted to share the issues to improve this great project! :-)

Command examples:

echo "foo bar" > /path/of/file ; cat /path/of/file
ip a
ls 

The use of SwiftSH is wrapped in a function, which is wrapped in a custom "SSH" NSObject. For each command I wanna execute, I'm creating a new SSH object, to separate all commands and connections.
I already tried to disconnect() and close() the Command objects or also storing them in arrays of long living objects but unfortunately I had no luck.
All commands are pretty simple (see the examples below) and every command has a timeout of 10 sec and is usually executed after 3 sec.

SSH().executeShortrunningSSHCommand(command, host: hostname, port: port, user: username, pwd: password) { (result, error) in
            completion(result, error)
}
var myCommand = Command(host:"hostname", port: 22)
        myCommand?.timeout = TimeInterval(10)
        
        // Connect
        myCommand!.connect { (connError) in
            if nil != connError {
                completion(nil, connError)
                myCommand?.disconnect(nil)
                return
            }
            
            // Authentication
            myCommand!.authenticate(AuthenticationChallenge.byPassword(username: "username", password: "password"), completion: { (authError) in
                if nil != authError {
                    completion(nil, authError)
                    myCommand?.disconnect(nil)
                    return
                }
                
                // Execute
                myCommand!.execute(fullCommand) { (command: String, result: String?, execError: Error?) -> Void in
                    completion(result, execError)
                    
                    myCommand?.disconnect({
                        myCommand = nil
                    })
                }
         }
}

screen shot 2018-08-24 at 00 21 59

screen shot 2018-08-24 at 00 04 50

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

No branches or pull requests

1 participant