From fd183af1cc249c8602d4f522f7c5ae8725b72a05 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Tue, 21 May 2019 14:26:01 +0200 Subject: [PATCH] Issue #3681 instrumented HttpFields Signed-off-by: Greg Wilkins --- .../org/eclipse/jetty/http/HttpFields.java | 82 +++++++++++++++---- .../eclipse/jetty/server/ResourceService.java | 1 + .../jetty/servlets/PushCacheFilter.java | 2 +- 3 files changed, 67 insertions(+), 18 deletions(-) diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java index 687d2a18c5f..0b6c00cebf8 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java @@ -61,9 +61,9 @@ public class HttpFields implements Iterable private HttpField[] _fields; private int _size; - private int iterations = 0; - private int lookups; + private int hits = 0; + private int misses = 0; /** @@ -95,6 +95,11 @@ public class HttpFields implements Iterable _size=fields._size; } + public void iterate() + { + iterations++; + } + public int size() { return _size; @@ -159,85 +164,106 @@ public class HttpFields implements Iterable public HttpField getField(HttpHeader header) { - lookups++; for (int i=0;i<_size;i++) { HttpField f=_fields[i]; if (f.getHeader()==header) + { + hits++; return f; + } } + misses++; return null; } public HttpField getField(String name) { - lookups++; for (int i=0;i<_size;i++) { HttpField f=_fields[i]; if (f.getName().equalsIgnoreCase(name)) + { + hits++; return f; + } } + misses++; return null; } public boolean contains(HttpField field) { - lookups++; for (int i=_size;i-->0;) { HttpField f=_fields[i]; if (f.isSameName(field) && (f.equals(field)||f.contains(field.getValue()))) + { + hits++; return true; + } } + misses++; return false; } public boolean contains(HttpHeader header, String value) { - lookups++; for (int i=_size;i-->0;) { HttpField f=_fields[i]; if (f.getHeader()==header && f.contains(value)) + { + hits++; return true; + } } + misses++; return false; } public boolean contains(String name, String value) { - lookups++; for (int i=_size;i-->0;) { HttpField f=_fields[i]; if (f.getName().equalsIgnoreCase(name) && f.contains(value)) + { + hits++; return true; + } } + misses++; return false; } public boolean contains(HttpHeader header) { - lookups++; for (int i=_size;i-->0;) { HttpField f=_fields[i]; if (f.getHeader()==header) + { + hits++; return true; + } } + misses++; return false; } public boolean containsKey(String name) { - lookups++; for (int i=_size;i-->0;) { HttpField f=_fields[i]; if (f.getName().equalsIgnoreCase(name)) + { + hits++; return true; + } } + misses++; return false; } @@ -249,13 +275,16 @@ public class HttpFields implements Iterable public String get(HttpHeader header) { - lookups++; for (int i=0;i<_size;i++) { HttpField f=_fields[i]; if (f.getHeader()==header) + { + hits++; return f.getValue(); + } } + misses++; return null; } @@ -267,13 +296,16 @@ public class HttpFields implements Iterable public String get(String header) { - lookups++; for (int i=0;i<_size;i++) { HttpField f=_fields[i]; if (f.getName().equalsIgnoreCase(header)) + { + hits++; return f.getValue(); + } } + misses++; return null; } @@ -285,11 +317,17 @@ public class HttpFields implements Iterable */ public List getValuesList(HttpHeader header) { - lookups++; final List list = new ArrayList<>(); for (HttpField f : this) + { if (f.getHeader()==header) list.add(f.getValue()); + } + if (list.isEmpty()) + misses++; + else + hits++; + return list; } @@ -301,11 +339,14 @@ public class HttpFields implements Iterable */ public List getValuesList(String name) { - lookups++; final List list = new ArrayList<>(); for (HttpField f : this) if (f.getName().equalsIgnoreCase(name)) list.add(f.getValue()); + if (list.isEmpty()) + misses++; + else + hits++; return list; } @@ -413,7 +454,6 @@ public class HttpFields implements Iterable */ public List getCSV(HttpHeader header,boolean keepQuotes) { - lookups++; QuotedCSV values = null; for (HttpField f : this) { @@ -424,6 +464,10 @@ public class HttpFields implements Iterable values.addValue(f.getValue()); } } + if (values==null) + misses++; + else + hits++; return values==null?Collections.emptyList():values.getValues(); } @@ -437,7 +481,6 @@ public class HttpFields implements Iterable */ public List getCSV(String name,boolean keepQuotes) { - lookups++; QuotedCSV values = null; for (HttpField f : this) { @@ -448,6 +491,10 @@ public class HttpFields implements Iterable values.addValue(f.getValue()); } } + if (values==null) + misses++; + else + hits++; return values==null?Collections.emptyList():values.getValues(); } @@ -924,9 +971,10 @@ public class HttpFields implements Iterable public void clear() { - System.err.printf("iterations=%d lookups=%d%n",iterations,lookups); + System.err.printf("iterations=%d hits=%d misses=%d%n",iterations,hits, misses); iterations = 0; - lookups = 0; + hits = 0; + misses = 0; _size=0; } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/ResourceService.java b/jetty-server/src/main/java/org/eclipse/jetty/server/ResourceService.java index 048bd714d89..bd26e747e87 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/ResourceService.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/ResourceService.java @@ -488,6 +488,7 @@ public class ResourceService { // Find multiple fields by iteration as an optimization HttpFields fields = ((Request)request).getHttpFields(); + fields.iterate(); for (int i=fields.size();i-->0;) { HttpField field=fields.getField(i); diff --git a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/PushCacheFilter.java b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/PushCacheFilter.java index 6bbd176b0d1..7c986c2620a 100644 --- a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/PushCacheFilter.java +++ b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/PushCacheFilter.java @@ -31,7 +31,6 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; - import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; @@ -140,6 +139,7 @@ public class PushCacheFilter implements Filter loop: for (int i = 0; i < fields.size(); i++) { + fields.iterate(); HttpField field = fields.getField(i); HttpHeader header = field.getHeader(); if (header == null)