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

Disable XML in conntrack parsing #2095

Merged
merged 5 commits into from
Dec 22, 2016
Merged

Disable XML in conntrack parsing #2095

merged 5 commits into from
Dec 22, 2016

Conversation

2opremio
Copy link
Contributor

This attempts to improve the performance problems from #1991

Parsing the default output of conntrack instead of XML turns out to be more difficult than we thought since some fields are optional and context-based.

I put together this hacky non-optimal parser to see if it's better than XML. If there's a considerable difference I will improve it and write a proper parser, otherwise I may just bite the bullet and fix vishvananda/netlink#171

@2opremio 2opremio changed the title [WIP] Diable XML in conntrack parsing [WIP] Disable XML in conntrack parsing Dec 15, 2016
@2opremio 2opremio force-pushed the 1991-conntrack-parsing branch from 0aba533 to 5c02dfc Compare December 19, 2016 18:56
@2opremio
Copy link
Contributor Author

After running this in WeaveCloud dev I can see a parsing improvement of 1-(1.74/1.01)*100 ~= 40%

This is a rough estimation and I should make further tests but it's promising.

Before (look for xml.(*Decoder).unmarshal taking 1.74s out of 30s)

before

After (look for decodeStreamedFlow taking 1.01s out of 30s)

after

@2opremio
Copy link
Contributor Author

2opremio commented Dec 20, 2016

I have made some more thorough testing: multiple runs, using a more loaded machine (similar to the one seen on #1985 (comment)) and making sure to compare probe pods running in the same machine. The results are even better than I thought: 1-(1.25/4.23) ~= 70% improvement.

Before:

before

After (focusing on decodeStreamedFlow):

after_streamed_2

So, I will clean this up, fix the tests and merge it.

@2opremio 2opremio force-pushed the 1991-conntrack-parsing branch 2 times, most recently from cd14b62 to 13ad063 Compare December 21, 2016 19:23
* Remove XML traces
* Improve performance
* Fix tests
@2opremio 2opremio force-pushed the 1991-conntrack-parsing branch from 13ad063 to d22d64c Compare December 21, 2016 19:35
@2opremio 2opremio changed the title [WIP] Disable XML in conntrack parsing Disable XML in conntrack parsing Dec 21, 2016
@2opremio 2opremio requested a review from ekimekim December 21, 2016 20:21

// Now loop on the output stream
decoder := xml.NewDecoder(reader)
// Lop on the output stream

This comment was marked as abuse.

Copy link
Contributor

@ekimekim ekimekim left a comment

Choose a reason for hiding this comment

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

lgtm.
I don't have a good intuition on performance of scanf, but as you've shown this is Better Than Live so we can work on tweaking the perf later.

Have you double-checked this output against various verisons of the conntrack CLI to ensure it will work with older versions? Is this format guarenteed to not change in the future?
These questions are non-blocking.

@2opremio
Copy link
Contributor Author

Have you double-checked this output against various verisons of the conntrack CLI to ensure it will work with older versions?

We control the version (i.e. the CLI included in the Scope container).

Is this format guarenteed to not change in the future?

It hasn't changed in a long time. The last conntrack-tools release is from 2012 http://conntrack-tools.netfilter.org/

@2opremio
Copy link
Contributor Author

2opremio commented Dec 22, 2016

It hasn't changed in a long time. The last conntrack-tools release is from 2012 http://conntrack-tools.netfilter.org/

I was wrong, http://www.netfilter.org/projects/conntrack-tools/downloads.html says otherwise. So, no guarantees but I would doubt it will change (it hasn't been heavily modified in the past years https://git.netfilter.org/conntrack-tools/log/src/conntrack.c )

@2opremio 2opremio merged commit 2cd7613 into master Dec 22, 2016
@2opremio 2opremio deleted the 1991-conntrack-parsing branch December 22, 2016 10:00
@alban
Copy link
Contributor

alban commented Jan 6, 2017

Have you double-checked this output against various verisons of the conntrack CLI to ensure it will work with older versions?

We control the version (i.e. the CLI included in the Scope container).

@2opremio unfortunately, the output depends not only on the version of conntrack CLI but also on the kernel and on the sysctl options configured (see #2117)

@alban alban mentioned this pull request Jan 9, 2017
2 tasks
alban added a commit to kinvolk-archives/scope that referenced this pull request Jan 13, 2017
With net.netfilter.nf_conntrack_acct = 1, conntrack adds the following
fields in the output: packets=3 bytes=164

And with SELinux (e.g. Fedora), conntrack adds: secctx=...

The parsing with fmt.Sscanf introduced in weaveworks#2095 was unfortunately
rejecting lines with those fields. This patch fixes that by adding more
complicated parsing in decodeTwoTuples() with FieldsFunc and SplitN.

Fixes weaveworks#2117
Regression from weaveworks#2095
@2opremio 2opremio mentioned this pull request Jan 16, 2017
alban added a commit to kinvolk-archives/scope that referenced this pull request Jan 17, 2017
With net.netfilter.nf_conntrack_acct = 1, conntrack adds the following
fields in the output: packets=3 bytes=164

And with SELinux (e.g. Fedora), conntrack adds: secctx=...

The parsing with fmt.Sscanf introduced in weaveworks#2095 was unfortunately
rejecting lines with those fields. This patch fixes that by adding more
complicated parsing in decodeFlowKeyValues() with FieldsFunc and SplitN.

Fixes weaveworks#2117
Regression from weaveworks#2095
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.

Add Conntrack support (NETLINK_NETFILTER protocol)
3 participants