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

Power management redesign #1891

Merged
merged 13 commits into from
Feb 14, 2023
Merged

Power management redesign #1891

merged 13 commits into from
Feb 14, 2023

Conversation

muhamadazmy
Copy link
Member

No description provided.

@muhamadazmy muhamadazmy force-pushed the power-management-redesign branch from 26855b5 to 170357f Compare February 14, 2023 12:51
@muhamadazmy muhamadazmy marked this pull request as ready for review February 14, 2023 13:11
// Module is entry point for module
var Module cli.Command = cli.Command{
Name: "powerd",
Usage: "reports the node total resources",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it do that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

of course not


cl, err := zbus.NewRedisClient(msgBrokerCon)
if err != nil {
return errors.Wrap(err, "fail to connect to message broker server")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fail -> failed

@@ -102,7 +102,7 @@ func (d *identityManager) Farm() (string, error) {
}
defer cl.Close()

farm, err := cl.GetFarm(uint32(d.env.FarmerID))
farm, err := cl.GetFarm(uint32(d.env.FarmID))
if errors.Is(err, substrate.ErrNotFound) {
return "", fmt.Errorf("wrong farm id")
} else if err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's do on a separate if condition no need for the else if here

continue
}
if len(parts) != 2 {
return "", fmt.Errorf("invalid ethtool output format")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we include the line for more debugging purposes in the error?

if errors.Is(err, ErrFlagNotFound) {
// no support for
return false, nil
} else if err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's move it outside of the else if

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really think it's more readable with the else if (specially if someone else going to work on this code) instead of multiple if

The reason is i think it's more readable, and probably optimized, is that it works in both cases if you return or not return in the branch. Also normally if u don't return the else if optimized the code so not all of the branches are checked

so

if cond1 {
}

if cond1 {
}

both will be checked in runtime

but using else if like

if cond1 {
} else if cond2 {
}

the compiler knows cond1 and cond2 can't both happen at the same time, hence if cond1 is true, cond2 is not checked.


func (p *PowerServer) shutdown() error {
if !p.enabled {
log.Info().Msg("ignoring shutdown because power managed is not enabled")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

power managed -> power management?

return p.events(ctx)
}

type Direct struct {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this struct mean/do?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Old code, will delete

}

func (p *PowerServer) syncSelf() error {
cl, err := p.sub.Substrate()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

substrate connection was never closed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks

Uint32("node", p.node).
Msg("received power event for farm")

cl, err := p.sub.Substrate()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

substrate connection never closed.

}

// start processing time events.
func (p *PowerServer) events(ctx context.Context) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would opening and closing the substrate connection here help a bit??

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm suggesting this because if there were many power management events, with each event being processed a substrate connection is opened, which may be costly???

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while the node receive all power events, not all events reaches here, only events intended to the node farm are actually propagated to this code

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So instead of holding an open connection all the time it's actually better to only open when needed which should not be many

} else if err != nil {
log.Error().Err(err).Msg("sending uptime failed")
} else {
// context was cancelled
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this the case where uptime is reported successfully?
I'm asking if context is really canceled here or not.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, if u follow the code you will see that the u.uptime() actually starts an infinite loop that only returns succefully if the ctx is cancelled and the node is shutdown. Any other error means we need to start this infinite loop again

@muhamadazmy muhamadazmy merged commit cb0403f into main Feb 14, 2023
@muhamadazmy muhamadazmy deleted the power-management-redesign branch February 14, 2023 16:58
@xmonader xmonader mentioned this pull request Feb 26, 2023
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

Successfully merging this pull request may close these issues.

3 participants