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

listen on ipv4 addresses - high cpu #269

Open
deekshithd opened this issue Dec 18, 2017 · 1 comment
Open

listen on ipv4 addresses - high cpu #269

deekshithd opened this issue Dec 18, 2017 · 1 comment

Comments

@deekshithd
Copy link

deekshithd commented Dec 18, 2017

Hi

I have multiple IPs mounted to my machine and using sniproxy, and I wanted to know on which IP the connection was accepted by sniproxy.

So, changed listen clauses in sniproxy config file to use ipv4 address (e.g. "listen a.b.c.d:8043 {...}"). After this change, seeing high cpu usage in sniproxy. Also, seeing high number of connection resets from client side. The client connections come thru a NAT.

Does anyone know what can be the issue here? Is this possible if the NAT from where connections are coming from using a mix of ipv4 and ipv6 connections? How does client behave if sniproxy only listening on ipv4 socket?

I assume to listen on both ipv4, and ipv6 and accept connections from both ipv4 and ipv6 end points, I should use the config like: "listen ::ffff:a.b.c.d:8043 {...}". Is this assumption correct?

Or can someone suggest what is the best way to know the IP address at which a connection was accepted, as well support both ipv4 and ipv6 connections coming to sniproxy?

Also, note that prior to this cpu issue, I was using "listen 8043 {...}" clause.

Thanks

@dlundquist
Copy link
Owner

@deekshithd if you just want to log the local socket address of the incoming client connection, you need to add a getsockname() call to accept_connection() and persist it in the connection object until log_connection() and use this instead of con->listener->address. This wasn't included because this information was not necessary, might be confusing when trying to match listener configuration to access logs, and required may have negatively impacted performance. It would be great to see some performance data with this change enabled, the profile-nonblocking-connect branch includes connection timestamping code that could be used to examine the performance impact of this change.

As for your high CPU usage when listening on IPv4 addresses, this is surprising. My usual approach is to enable debug logging, and look for any unusual activity, then take a look at systrace. Can you reproduce this high CPU usage without NAT?

A listener bound to an specific IPv6 address (i.e. not ::) should only accept connections from IPv6 clients, only ::/in6addr_any is special in this regard. This sounds like another case for adding a configuration knob for IPV6_V6ONLY to selectively disable accepting IPv4 connections on IPbv6 listeners.

dlundquist added a commit that referenced this issue Dec 18, 2017
Persist local socket addresses for both client and server connections in
connection object. Modify access log to use actual address connection
was accepted on rather than listener address. This way when listening on
0.0.0.0 or :: will log the address the client connected to.

This increases the size of the connection object and may otherwise
negatively affect performance due to addition of getsockname() calls.

GitHub issue #269
caveat emptor
dlundquist added a commit that referenced this issue Mar 3, 2018
Persist local socket addresses for both client and server connections in
connection object. Modify access log to use actual address connection
was accepted on rather than listener address. This way when listening on
0.0.0.0 or :: will log the address the client connected to.

This increases the size of the connection object and may otherwise
negatively affect performance due to addition of getsockname() calls.

GitHub issue #269
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

2 participants