Skip to content

Regexp tidy up#978

Merged
jimmidyson merged 1 commit into
google:masterfrom
jimmidyson:regexp-perf
Nov 26, 2015
Merged

Regexp tidy up#978
jimmidyson merged 1 commit into
google:masterfrom
jimmidyson:regexp-perf

Conversation

@jimmidyson
Copy link
Copy Markdown
Contributor

Cleaned up some areas where regexps were either messy or unnecessary.

Comment thread container/docker/factory.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why move this out of the function? Personally I find it more readable if I can see the regexp right where it's used (and I don't think this should be used outside that function).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Putting it in the function means the RE gets wastefully compiled every time the function is called. In this case probably not called more than once, but normally best to move it outside so trying to keep it consistent.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, makes sense. Maybe move the declaration to just above the function in that case? Also, consider making the string const.

@timstclair timstclair self-assigned this Nov 25, 2015
Comment thread container/libcontainer/helpers.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(nit) space after //

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also this comment reads a little weird. Maybe rephrase to:

// TCP state is the 4th field.
// Format: sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt  uid timeout inode

@jimmidyson
Copy link
Copy Markdown
Contributor Author

@timstclair Thanks for a thorough code review - this is making it a much more worthwhile endeavour than it would have otherwise been :)

Comment thread utils/sysinfo/sysinfo.go
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This regex should use a raw string too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

@timstclair
Copy link
Copy Markdown
Contributor

@timstclair Thanks for a thorough code review - this is making it a much more worthwhile endeavour than it would have otherwise been :)

No problem! Thanks for the cleanup!

@jimmidyson
Copy link
Copy Markdown
Contributor Author

All comments addressed. Good review!

@jimmidyson
Copy link
Copy Markdown
Contributor Author

As an observation there is a lot we could do to lower resource utilisation. Regexps are hungry & need to be used judiciously. They're overused here where we could probably do some cheaper string parsing.

@jimmidyson
Copy link
Copy Markdown
Contributor Author

Integration tests pass, so it must be good right? 😜

Comment thread utils/machine/machine.go
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This whole loop could use some cleanup. I think it would be much more efficient and readable to switch on strings.TrimSpace(line[:strings.Index(line, ":")-1])

That's sort of a separate change, so up to you where / whether you want to address it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed. Not going to do it here, luckily AFAICT this is only called once on start of cadvisor so efficiency isn't paramount. Would like to improve it though, for vanity more than anything else :-b

@timstclair
Copy link
Copy Markdown
Contributor

LGTM (please squash)

Integration tests pass, so it must be good right?

Of course! I always like to have some simple unit tests for regexes, but I won't force you to add them if you aren't up for it...

As an observation there is a lot we could do to lower resource utilisation. Regexps are hungry & need to be used judiciously. They're overused here where we could probably do some cheaper string parsing.

Agreed. Although I don't think it's worth spending too much time on this without first doing some profiling to identify the places it really matters.

@jimmidyson
Copy link
Copy Markdown
Contributor Author

Yeah we need to do more profiling of cadvisor in general. There have been quite a few performance issues when embedded in the kubelet & we need to identify areas for improvement. Regexes were a recurrent theme in those perf problems, hence me looking at them here. I think with the work we've done recently in cadvisor this is improved significantly, but further work needs to be done to keep cadvisor's footprint as low as possible.

@jimmidyson
Copy link
Copy Markdown
Contributor Author

retest this please

@jimmidyson
Copy link
Copy Markdown
Contributor Author

Self-merging after LGTM.

jimmidyson added a commit that referenced this pull request Nov 26, 2015
@jimmidyson jimmidyson merged commit cec96eb into google:master Nov 26, 2015
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.

2 participants