lantern icon indicating copy to clipboard operation
lantern copied to clipboard

excessive debug logs from flashlight in developer mode

Open ed2k opened this issue 12 years ago • 27 comments

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) {

ed2k avatar Oct 11 '14 16:10 ed2k

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?

myleshorton avatar Oct 14 '14 18:10 myleshorton

It's just this debug statement. I think we should just take it out.

oxtoacart avatar Oct 14 '14 18:10 oxtoacart

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.

myleshorton avatar Oct 14 '14 18:10 myleshorton

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.

ed2k avatar Oct 14 '14 18:10 ed2k

You'll see bursts in activity as the TCP connection pool is filled. To reproduce:

  1. Start proxy
  2. Make a request to a single url, note that a bunch of these statements get logged
  3. Make another request to a single url, note that only one of these statements gets logged

oxtoacart avatar Oct 14 '14 18:10 oxtoacart

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.

oxtoacart avatar Oct 14 '14 18:10 oxtoacart

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.

myleshorton avatar Oct 14 '14 18:10 myleshorton

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.

oxtoacart avatar Oct 26 '14 12:10 oxtoacart

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.

oxtoacart avatar Oct 26 '14 14:10 oxtoacart

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.

oxtoacart avatar Oct 26 '14 16:10 oxtoacart

Okay, I was able to reliably reproduce the CPU spike.

Starting with no flashlight.yaml:

  1. Run flashlight in role client on port 10080
  2. curl -x localhost:10080 http://www.google.com/humans.txt
  3. Note that curl completes in a timely fashion
  4. Edit the generated flashlight.yaml to change roundrobin.getiantem.org to fallbacks.getiantem.org
  5. Note that the log starts showing the "long dial" warning and CPU usage spikes to 100% and stays there

oxtoacart avatar Oct 26 '14 16:10 oxtoacart

If you kill flashlight, then start it, then follow this sequence, the CPU spike happens again:

  1. curl -x localhost:10080 http://www.google.com/humans.txt
  2. Edit flashlight.yaml to change fallbacks.getiantem.org back to roundrobin.getiantem.org

oxtoacart avatar Oct 26 '14 16:10 oxtoacart

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!)

oxtoacart avatar Oct 26 '14 16:10 oxtoacart

Upgrading to go 1.3.3 didn't fix the problem.

oxtoacart avatar Oct 26 '14 17:10 oxtoacart

is the problem narrowed down to too many TCP connections revealed by lsof -p pid?

ed2k avatar Oct 26 '14 17:10 ed2k

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.

oxtoacart avatar Oct 26 '14 17:10 oxtoacart

is there golang profiler?

ed2k avatar Oct 26 '14 17:10 ed2k

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.

oxtoacart avatar Oct 26 '14 17:10 oxtoacart

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.

oxtoacart avatar Oct 26 '14 17:10 oxtoacart

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.

oxtoacart avatar Oct 27 '14 01:10 oxtoacart