excessive debug logs from flashlight in developer mode
don't know what is changed, recently this kind of line "Using masquerade minecraftforum.net" sometimes will be printed hundreds of times in a second. have to apply this change
diff --git a/src/main/java/org/lantern/proxy/pt/LoggingStreamHandler.java b/src/main/java/org/lantern/proxy/pt/LoggingStreamHandler.java
index a1cb077..6c8a0ea 100644
--- a/src/main/java/org/lantern/proxy/pt/LoggingStreamHandler.java
+++ b/src/main/java/org/lantern/proxy/pt/LoggingStreamHandler.java
@@ -95,12 +95,16 @@ public class LoggingStreamHandler implements ExecuteStreamHandler {
@Override
public void run() {
String line = null;
+ String prevLine = null;
try {
while ((line = reader.readLine()) != null) {
if (logToError) {
log.error(line);
} else {
- log.debug(line);
+ if (!line.equals(prevLine)) {
+ log.debug(line);
+ prevLine = line;
+ }
}
}
} catch (IOException ioe) {
Thanks @ed2k. Hey @oxtoacart any idea why we'd be getting so many logs from the backend. I can see this fixes it @ed2k but it would be nice to figure out what the root cause is. Does it happen when you're really hitting a lot of sites?
It's just this debug statement. I think we should just take it out.
Works for me. It's a little surprising it would be printed hundreds of times a second though no?
On Tue, Oct 14, 2014 at 11:44 AM, oxtoacart [email protected] wrote:
It's just this debug statement https://github.com/getlantern/flashlight/blob/master/client/server.go#L92. I think we should just take it out.
— Reply to this email directly or view it on GitHub https://github.com/getlantern/lantern/issues/1895#issuecomment-59095540.
I put some counters to see how many repeated times it is. at some point it could 65xxx repeated times. looks really strange.
On Tue, Oct 14, 2014 at 11:48 AM, myleshorton [email protected] wrote:
Works for me. It's a little surprising it would be printed hundreds of times a second though no?
On Tue, Oct 14, 2014 at 11:44 AM, oxtoacart [email protected] wrote:
It's just this debug statement < https://github.com/getlantern/flashlight/blob/master/client/server.go#L92>.
I think we should just take it out.
— Reply to this email directly or view it on GitHub https://github.com/getlantern/lantern/issues/1895#issuecomment-59095540.
— Reply to this email directly or view it on GitHub https://github.com/getlantern/lantern/issues/1895#issuecomment-59096017.
You'll see bursts in activity as the TCP connection pool is filled. To reproduce:
- Start proxy
- Make a request to a single url, note that a bunch of these statements get logged
- Make another request to a single url, note that only one of these statements gets logged
Oh, and if you wait a bit, the connections in the pool will time out, so then making another request will result in another burst of these statements being logged.
Gotcha. OK yeah let's just take it out.
On Tue, Oct 14, 2014 at 11:55 AM, oxtoacart [email protected] wrote:
Oh, and if you wait a bit, the connections in the pool will time out, so then making another request will result in another burst of these statements being logged.
— Reply to this email directly or view it on GitHub https://github.com/getlantern/lantern/issues/1895#issuecomment-59097242.
There was a problem here. I added a unit test to package connpool to reproduce it, then fixed the problem.
I'll be using the updated flashlight for all my web browsing today to see how it does in practice.
I'm getting long dial errors if I change the flashlight.yaml configuration. Need to look into the code path for when the configuration is updated.
I just had the CPU spike to 100%, even after my fixes to the connection pooling. It seems to be related to these long dial errors somehow.
Okay, I was able to reliably reproduce the CPU spike.
Starting with no flashlight.yaml:
- Run flashlight in role client on port 10080
curl -x localhost:10080 http://www.google.com/humans.txt- Note that curl completes in a timely fashion
- Edit the generated flashlight.yaml to change roundrobin.getiantem.org to fallbacks.getiantem.org
- Note that the log starts showing the "long dial" warning and CPU usage spikes to 100% and stays there
If you kill flashlight, then start it, then follow this sequence, the CPU spike happens again:
curl -x localhost:10080 http://www.google.com/humans.txt- Edit flashlight.yaml to change fallbacks.getiantem.org back to roundrobin.getiantem.org
I added some trace logging to tlsdialer, and I see that what's taking a long time is the handshaking (takes over 2 seconds once the error is encountered!)
Upgrading to go 1.3.3 didn't fix the problem.
is the problem narrowed down to too many TCP connections revealed by lsof -p pid?
There appear to be two problems. connpool was opening too many TCP connections, but there's something else going on that's pinning the CPU.
is there golang profiler?
Yes, and you can enable profiling in flashlight using the -cpuprofile flag. But the profiler doesn't work on Mac without patching the kernel. Will try on Linux if I need to. But I think I've found the problem.
Okay, the problem with the CPU usage that I saw was actually introduced by my change to connpool. The Stop() method ended up causing a runaway loop. That's solved now, and CPU usage looks good both after initial start and after changing the configuration.
I've been browsing using flashlight for 4 hours now. CPU usage is still around 2-3%, resident size is 28.3 MB and TCP file descriptors are in the 60-100 range.