[GitHub] tomcat issue #126: The feature of the transfer rate control are added to the...

2018-10-12 Thread rmaucher
Github user rmaucher commented on the issue:

https://github.com/apache/tomcat/pull/126
  
-1 from me. This is a bad combination of too big and too specific to be 
included IMO. Also, and more importantly, it will replace a non blocking / 
async IO feature with something that uses threads like a regular servlet does.


---

-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



[GitHub] tomcat pull request #126: The feature of the transfer rate control are added...

2018-10-12 Thread rmaucher
Github user rmaucher commented on a diff in the pull request:

https://github.com/apache/tomcat/pull/126#discussion_r224803205
  
--- Diff: java/org/apache/tomcat/util/net/RateLimiter.java ---
@@ -0,0 +1,163 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tomcat.util.net;
+
+import java.io.IOException;
+
+/** Abstract base class to rate limit IO.  Typically implementations are
+ *  shared across multiple IndexInputs or IndexOutputs (for example
+ *  those involved all merging).  Those IndexInputs and
+ *  IndexOutputs would call {@link #pause} whenever the have read
+ *  or written more than {@link #getMinPauseCheckBytes} bytes. */
+public abstract class RateLimiter {
+
+  /**
+   * Sets an updated MB per second rate limit.
+   */
+  public abstract void setMBPerSec(double mbPerSec);
+
+  /**
+   * The current MB per second rate limit.
+   */
+  public abstract double getMBPerSec();
+  
+  /** Pauses, if necessary, to keep the instantaneous IO
+   *  rate at or below the target. 
+   *  
+   *  Note: the implementation is thread-safe
+   *  
+   *  @return the pause time in nano seconds 
+   * */
+  public abstract long pause(long bytes);
+  
+  /** How many bytes caller should add up itself before invoking {@link 
#pause}. */
+  public abstract long getMinPauseCheckBytes();
+
+  /**
+   * Simple class to rate limit IO.
+   */
+  public static class SimpleRateLimiter extends RateLimiter {
+
+private final static int MIN_PAUSE_CHECK_MSEC = 5;
+
+private volatile double mbPerSec;
+private volatile long minPauseCheckBytes;
+private long lastNS;
+
+// TODO: we could also allow eg a sub class to dynamically
+// determine the allowed rate, eg if an app wants to
+// change the allowed rate over time or something
+
+/** mbPerSec is the MB/sec max IO rate */
+public SimpleRateLimiter(double mbPerSec) {
+  setMBPerSec(mbPerSec);
+  lastNS = System.nanoTime();
+}
+
+/**
+ * Sets an updated mb per second rate limit.
+ */
+@Override
+public void setMBPerSec(double mbPerSec) {
+  this.mbPerSec = mbPerSec;
+  minPauseCheckBytes = (long) ((MIN_PAUSE_CHECK_MSEC / 1000.0) * 
mbPerSec * 1024 * 1024);
+}
+
+@Override
+public long getMinPauseCheckBytes() {
+  return minPauseCheckBytes;
+}
+
+/**
+ * The current mb per second rate limit.
+ */
+@Override
+public double getMBPerSec() {
+  return this.mbPerSec;
+}
+
+/** Pauses, if necessary, to keep the instantaneous IO
+ *  rate at or below the target.  Be sure to only call
+ *  this method when bytes > {@link #getMinPauseCheckBytes},
+ *  otherwise it will pause way too long!
+ *
+ *  @return the pause time in nano seconds */  
+@Override
+public long pause(long bytes) {
+
+  long startNS = System.nanoTime();
+
+  double secondsToPause = (bytes/1024./1024.) / mbPerSec;
+
+  long targetNS;
+
+  // Sync'd to read + write lastNS:
+  synchronized (this) {
+
+// Time we should sleep until; this is purely instantaneous
+// rate (just adds seconds onto the last time we had paused to);
+// maybe we should also offer decayed recent history one?
+targetNS = lastNS + (long) (10 * secondsToPause);
+
+if (startNS >= targetNS) {
+  // OK, current time is already beyond the target sleep time,
+  // no pausing to do.
+
+  // Set to startNS, not targetNS, to enforce the instant rate, not
+  // the "averaaged over all history" rate:
+  lastNS = startNS;
+  return 0;
+ 

[GitHub] tomcat issue #126: The feature of the transfer rate control are added to the...

2018-10-13 Thread rmaucher
Github user rmaucher commented on the issue:

https://github.com/apache/tomcat/pull/126
  
Ok. But this portion of the code in the connectors is asynchronous, so a 
throttling solution based on Thread.sleep isn't good enough for inclusion. A 
throttling feature, by itself, would be acceptable but could use a bit of prior 
discussion to make sure everyone is ok with the plan.

We're completely fine if you are using ngnix or httpd as a proxy for your 
throttling needs (and others), as a matter of fact Tomcat conspicuously does 
not implement proxying and we are actively recommending usage of 
httpd/mod_proxy/balancer for this purpose.


---

-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



[GitHub] tomcat issue #125: Provide port offset functionality (BZ-61171)

2018-10-29 Thread rmaucher
Github user rmaucher commented on the issue:

https://github.com/apache/tomcat/pull/125
  
Ok, so I'm guilty for all the system properties in Tomcat ... Sorry. So 
now, it's not good anymore. System properties are still fine for end users, but 
only by using ${...} property replacement in server.xml.


---

-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



[GitHub] tomcat issue #134: Display generate date when showing every message in Html ...

2018-11-18 Thread rmaucher
Github user rmaucher commented on the issue:

https://github.com/apache/tomcat/pull/134
  
I'm not convinced by the use case, so I don't see why this one adds 
something useful. Right-click + pageinfo wouldn't show the needed info ?


---

-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



[GitHub] tomcat issue #134: Display generate date when showing every message in Html ...

2018-11-19 Thread rmaucher
Github user rmaucher commented on the issue:

https://github.com/apache/tomcat/pull/134
  
Correct, this doesn't give the right info, I thought it did. Still not that 
convinced though, you don't see that kind of timestamp often (if at all), right 
?


---

-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



[GitHub] tomcat issue #73: Bug 57767 - Websocket client proprietary configuration

2017-10-13 Thread rmaucher
Github user rmaucher commented on the issue:

https://github.com/apache/tomcat/pull/73
  
Well, it looks ok to me overall, so I'll add a bit of javadoc and merge it. 
Any issue with backporting it ?


---

-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



[GitHub] tomcat issue #84: Add tomcat in the cloud abstract implementation

2017-11-17 Thread rmaucher
Github user rmaucher commented on the issue:

https://github.com/apache/tomcat/pull/84
  
Abstraction is ok, more importantly limiting the number of impls will make 
it much much easier to maintain.


---

-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org