comparison src/org/eclipse/jetty/server/AbstractConnector.java @ 818:ad292e148964

remove util/statistic
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 09 Sep 2016 17:09:20 -0600
parents 3428c60d7cfc
children 8e9db0bbf4f9
comparison
equal deleted inserted replaced
817:eb33d0045bc2 818:ad292e148964
38 import org.eclipse.jetty.io.EofException; 38 import org.eclipse.jetty.io.EofException;
39 import org.eclipse.jetty.util.component.AggregateLifeCycle; 39 import org.eclipse.jetty.util.component.AggregateLifeCycle;
40 import org.eclipse.jetty.util.component.Dumpable; 40 import org.eclipse.jetty.util.component.Dumpable;
41 import org.eclipse.jetty.util.log.Log; 41 import org.eclipse.jetty.util.log.Log;
42 import org.eclipse.jetty.util.log.Logger; 42 import org.eclipse.jetty.util.log.Logger;
43 import org.eclipse.jetty.util.statistic.CounterStatistic;
44 import org.eclipse.jetty.util.statistic.SampleStatistic;
45 import org.eclipse.jetty.util.thread.ThreadPool; 43 import org.eclipse.jetty.util.thread.ThreadPool;
46 44
47 /** 45 /**
48 * Abstract Connector implementation. This abstract implementation of the Connector interface provides: 46 * Abstract Connector implementation. This abstract implementation of the Connector interface provides:
49 * <ul> 47 * <ul>
87 protected int _maxIdleTime = 200000; 85 protected int _maxIdleTime = 200000;
88 protected int _lowResourceMaxIdleTime = -1; 86 protected int _lowResourceMaxIdleTime = -1;
89 protected int _soLingerTime = -1; 87 protected int _soLingerTime = -1;
90 88
91 private transient Thread[] _acceptorThreads; 89 private transient Thread[] _acceptorThreads;
92
93 private final AtomicLong _statsStartedAt = new AtomicLong(-1L);
94
95 /** connections to server */
96 private final CounterStatistic _connectionStats = new CounterStatistic();
97 /** requests per connection */
98 private final SampleStatistic _requestStats = new SampleStatistic();
99 /** duration of a connection */
100 private final SampleStatistic _connectionDurationStats = new SampleStatistic();
101 90
102 protected final HttpBuffersImpl _buffers = new HttpBuffersImpl(); 91 protected final HttpBuffersImpl _buffers = new HttpBuffersImpl();
103 92
104 /* ------------------------------------------------------------ */ 93 /* ------------------------------------------------------------ */
105 /** 94 /**
983 { 972 {
984 _name = name; 973 _name = name;
985 } 974 }
986 975
987 /* ------------------------------------------------------------ */ 976 /* ------------------------------------------------------------ */
988 /**
989 * @return Get the number of requests handled by this connector since last call of statsReset(). If setStatsOn(false) then this is undefined.
990 */
991 public int getRequests()
992 {
993 return (int)_requestStats.getTotal();
994 }
995
996 /* ------------------------------------------------------------ */
997 /**
998 * @return Returns the connectionsDurationTotal.
999 */
1000 public long getConnectionsDurationTotal()
1001 {
1002 return _connectionDurationStats.getTotal();
1003 }
1004
1005 /* ------------------------------------------------------------ */
1006 /**
1007 * @return Number of connections accepted by the server since statsReset() called. Undefined if setStatsOn(false).
1008 */
1009 public int getConnections()
1010 {
1011 return (int)_connectionStats.getTotal();
1012 }
1013
1014 /* ------------------------------------------------------------ */
1015 /**
1016 * @return Number of connections currently open that were opened since statsReset() called. Undefined if setStatsOn(false).
1017 */
1018 public int getConnectionsOpen()
1019 {
1020 return (int)_connectionStats.getCurrent();
1021 }
1022
1023 /* ------------------------------------------------------------ */
1024 /**
1025 * @return Maximum number of connections opened simultaneously since statsReset() called. Undefined if setStatsOn(false).
1026 */
1027 public int getConnectionsOpenMax()
1028 {
1029 return (int)_connectionStats.getMax();
1030 }
1031
1032 /* ------------------------------------------------------------ */
1033 /**
1034 * @return Mean duration in milliseconds of open connections since statsReset() called. Undefined if setStatsOn(false).
1035 */
1036 public double getConnectionsDurationMean()
1037 {
1038 return _connectionDurationStats.getMean();
1039 }
1040
1041 /* ------------------------------------------------------------ */
1042 /**
1043 * @return Maximum duration in milliseconds of an open connection since statsReset() called. Undefined if setStatsOn(false).
1044 */
1045 public long getConnectionsDurationMax()
1046 {
1047 return _connectionDurationStats.getMax();
1048 }
1049
1050 /* ------------------------------------------------------------ */
1051 /**
1052 * @return Standard deviation of duration in milliseconds of open connections since statsReset() called. Undefined if setStatsOn(false).
1053 */
1054 public double getConnectionsDurationStdDev()
1055 {
1056 return _connectionDurationStats.getStdDev();
1057 }
1058
1059 /* ------------------------------------------------------------ */
1060 /**
1061 * @return Mean number of requests per connection since statsReset() called. Undefined if setStatsOn(false).
1062 */
1063 public double getConnectionsRequestsMean()
1064 {
1065 return _requestStats.getMean();
1066 }
1067
1068 /* ------------------------------------------------------------ */
1069 /**
1070 * @return Maximum number of requests per connection since statsReset() called. Undefined if setStatsOn(false).
1071 */
1072 public int getConnectionsRequestsMax()
1073 {
1074 return (int)_requestStats.getMax();
1075 }
1076
1077 /* ------------------------------------------------------------ */
1078 /**
1079 * @return Standard deviation of number of requests per connection since statsReset() called. Undefined if setStatsOn(false).
1080 */
1081 public double getConnectionsRequestsStdDev()
1082 {
1083 return _requestStats.getStdDev();
1084 }
1085
1086 /* ------------------------------------------------------------ */
1087 /**
1088 * Reset statistics.
1089 */
1090 public void statsReset()
1091 {
1092 updateNotEqual(_statsStartedAt,-1,System.currentTimeMillis());
1093
1094 _requestStats.reset();
1095 _connectionStats.reset();
1096 _connectionDurationStats.reset();
1097 }
1098
1099 /* ------------------------------------------------------------ */
1100 public void setStatsOn(boolean on)
1101 {
1102 if (on && _statsStartedAt.get() != -1)
1103 return;
1104
1105 if (LOG.isDebugEnabled())
1106 LOG.debug("Statistics on = " + on + " for " + this);
1107
1108 statsReset();
1109 _statsStartedAt.set(on?System.currentTimeMillis():-1);
1110 }
1111
1112 /* ------------------------------------------------------------ */
1113 /**
1114 * @return True if statistics collection is turned on.
1115 */
1116 public boolean getStatsOn()
1117 {
1118 return _statsStartedAt.get() != -1;
1119 }
1120
1121 /* ------------------------------------------------------------ */
1122 /**
1123 * @return Timestamp stats were started at.
1124 */
1125 public long getStatsOnMs()
1126 {
1127 long start = _statsStartedAt.get();
1128
1129 return (start != -1)?(System.currentTimeMillis() - start):0;
1130 }
1131
1132 /* ------------------------------------------------------------ */
1133 protected void connectionOpened(Connection connection) 977 protected void connectionOpened(Connection connection)
1134 { 978 {
1135 if (_statsStartedAt.get() == -1)
1136 return;
1137
1138 _connectionStats.increment();
1139 } 979 }
1140 980
1141 /* ------------------------------------------------------------ */ 981 /* ------------------------------------------------------------ */
1142 protected void connectionUpgraded(Connection oldConnection, Connection newConnection) 982 protected void connectionUpgraded(Connection oldConnection, Connection newConnection)
1143 { 983 {
1144 _requestStats.set((oldConnection instanceof AbstractHttpConnection)?((AbstractHttpConnection)oldConnection).getRequests():0);
1145 } 984 }
1146 985
1147 /* ------------------------------------------------------------ */ 986 /* ------------------------------------------------------------ */
1148 protected void connectionClosed(Connection connection) 987 protected void connectionClosed(Connection connection)
1149 { 988 {
1150 connection.onClose(); 989 connection.onClose();
1151
1152 if (_statsStartedAt.get() == -1)
1153 return;
1154
1155 long duration = System.currentTimeMillis() - connection.getTimeStamp();
1156 int requests = (connection instanceof AbstractHttpConnection)?((AbstractHttpConnection)connection).getRequests():0;
1157 _requestStats.set(requests);
1158 _connectionStats.decrement();
1159 _connectionDurationStats.set(duration);
1160 } 990 }
1161 991
1162 /* ------------------------------------------------------------ */ 992 /* ------------------------------------------------------------ */
1163 /** 993 /**
1164 * @return the acceptorPriority 994 * @return the acceptorPriority