cvs commit: jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/buf StringCache.java

2004-10-25 Thread remm
remm2004/10/25 08:28:23

  Modified:catalina/src/share/org/apache/catalina/core
StandardServer.java
   util/java/org/apache/tomcat/util/buf StringCache.java
  Log:
  - Make StringCache a fake JavaBean, so that it can be exposed in JMX in 
StandardServer.
  
  Revision  ChangesPath
  1.39  +12 -1 
jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardServer.java
  
  Index: StandardServer.java
  ===
  RCS file: 
/home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardServer.java,v
  retrieving revision 1.38
  retrieving revision 1.39
  diff -u -r1.38 -r1.39
  --- StandardServer.java   4 Oct 2004 13:26:47 -   1.38
  +++ StandardServer.java   25 Oct 2004 15:28:23 -  1.39
  @@ -77,6 +77,7 @@
   import org.apache.commons.modeler.Registry;
   import org.apache.coyote.ProtocolHandler;
   import org.apache.tomcat.util.IntrospectionUtils;
  +import org.apache.tomcat.util.buf.StringCache;
   
   
   
  @@ -2075,6 +2076,16 @@
   }
   }
   
  +// Register global String cache
  +try {
  +ObjectName oname2 = 
  +new ObjectName(oname.getDomain() + :type=StringCache);
  +Registry.getRegistry(null, null)
  +.registerComponent(new StringCache(), oname2, null );
  +} catch (Exception e) {
  +log.error(Error registering ,e);
  +}
  +
   // Initialize our defined Services
   for (int i = 0; i  services.length; i++) {
   services[i].initialize();
  
  
  
  1.4   +11 -11
jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/buf/StringCache.java
  
  Index: StringCache.java
  ===
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/buf/StringCache.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- StringCache.java  20 Oct 2004 12:28:06 -  1.3
  +++ StringCache.java  25 Oct 2004 15:28:23 -  1.4
  @@ -109,7 +109,7 @@
   /**
* @return Returns the cacheSize.
*/
  -public static int getCacheSize() {
  +public int getCacheSize() {
   return cacheSize;
   }
   
  @@ -117,7 +117,7 @@
   /**
* @param cacheSize The cacheSize to set.
*/
  -public static void setCacheSize(int cacheSize) {
  +public void setCacheSize(int cacheSize) {
   StringCache.cacheSize = cacheSize;
   }
   
  @@ -125,7 +125,7 @@
   /**
* @return Returns the enabled.
*/
  -public static boolean getByteEnabled() {
  +public boolean getByteEnabled() {
   return byteEnabled;
   }
   
  @@ -133,7 +133,7 @@
   /**
* @param enabled The enabled to set.
*/
  -public static void setByteEnabled(boolean byteEnabled) {
  +public void setByteEnabled(boolean byteEnabled) {
   StringCache.byteEnabled = byteEnabled;
   }
   
  @@ -141,7 +141,7 @@
   /**
* @return Returns the enabled.
*/
  -public static boolean getCharEnabled() {
  +public boolean getCharEnabled() {
   return charEnabled;
   }
   
  @@ -149,7 +149,7 @@
   /**
* @param enabled The enabled to set.
*/
  -public static void setCharEnabled(boolean charEnabled) {
  +public void setCharEnabled(boolean charEnabled) {
   StringCache.charEnabled = charEnabled;
   }
   
  @@ -157,7 +157,7 @@
   /**
* @return Returns the trainThreshold.
*/
  -public static int getTrainThreshold() {
  +public int getTrainThreshold() {
   return trainThreshold;
   }
   
  @@ -165,7 +165,7 @@
   /**
* @param trainThreshold The trainThreshold to set.
*/
  -public static void setTrainThreshold(int trainThreshold) {
  +public void setTrainThreshold(int trainThreshold) {
   StringCache.trainThreshold = trainThreshold;
   }
   
  @@ -173,7 +173,7 @@
   /**
* @return Returns the accessCount.
*/
  -public static int getAccessCount() {
  +public int getAccessCount() {
   return accessCount;
   }
   
  @@ -181,7 +181,7 @@
   /**
* @return Returns the hitCount.
*/
  -public static int getHitCount() {
  +public int getHitCount() {
   return hitCount;
   }
   
  @@ -189,7 +189,7 @@
   // -- Public Static Methods
   
   
  -public static void reset() {
  +public void reset() {
   hitCount = 0;
   accessCount = 0;
   synchronized (bcStats) {
  
  
  

-
To unsubscribe, e-mail: [EMAIL 

cvs commit: jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/buf StringCache.java

2004-10-20 Thread remm
remm2004/10/20 05:28:06

  Modified:util/java/org/apache/tomcat/util/buf StringCache.java
  Log:
  - Change the default value for the cache size, as there's no use keeping seldom used 
strings.
  
  Revision  ChangesPath
  1.3   +1 -1  
jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/buf/StringCache.java
  
  Index: StringCache.java
  ===
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/buf/StringCache.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- StringCache.java  19 Oct 2004 09:28:58 -  1.2
  +++ StringCache.java  20 Oct 2004 12:28:06 -  1.3
  @@ -52,7 +52,7 @@
   
   
   protected static int cacheSize = 
  -
Integer.parseInt(System.getProperty(tomcat.util.buf.StringCache.cacheSize, 1000));
  +
Integer.parseInt(System.getProperty(tomcat.util.buf.StringCache.cacheSize, 200));
   
   
   /**
  
  
  

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



cvs commit: jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/buf StringCache.java

2004-10-19 Thread remm
remm2004/10/19 02:28:58

  Modified:util/java/org/apache/tomcat/util/buf StringCache.java
  Log:
  - Build the caches using a temp array.
  
  Revision  ChangesPath
  1.2   +22 -20
jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/buf/StringCache.java
  
  Index: StringCache.java
  ===
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/buf/StringCache.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StringCache.java  18 Oct 2004 23:16:36 -  1.1
  +++ StringCache.java  19 Oct 2004 09:28:58 -  1.2
  @@ -244,7 +244,7 @@
   if (size  cacheSize) {
   size = cacheSize;
   }
  -bcCache = new ByteEntry[size];
  +ByteEntry[] tempbcCache = new ByteEntry[size];
   // Fill it up using an alphabetical order
   // and a dumb insert sort
   ByteChunk tempChunk = new ByteChunk();
  @@ -257,13 +257,13 @@
   for (int i = 0; i  list.size()  n  size; i++) {
   ByteEntry entry = (ByteEntry) list.get(i);
   tempChunk.setBytes(entry.name, 0, 
entry.name.length);
  -int insertPos = findClosest(tempChunk, n);
  +int insertPos = findClosest(tempChunk, tempbcCache, 
n);
   if (insertPos == n) {
  -bcCache[n + 1] = entry;
  +tempbcCache[n + 1] = entry;
   } else {
  -System.arraycopy(bcCache, insertPos + 1, 
bcCache, 
  +System.arraycopy(tempbcCache, insertPos + 1, 
tempbcCache, 
   insertPos + 2, n - insertPos - 1);
  -bcCache[insertPos + 1] = entry;
  +tempbcCache[insertPos + 1] = entry;
   }
   n++;
   }
  @@ -271,6 +271,7 @@
   }
   bcCount = 0;
   bcStats.clear();
  +bcCache = tempbcCache;
   if (log.isDebugEnabled()) {
   long t2 = System.currentTimeMillis();
   log.debug(ByteCache generation time:  + (t2 - t1) + 
ms);
  @@ -357,7 +358,7 @@
   if (size  cacheSize) {
   size = cacheSize;
   }
  -ccCache = new CharEntry[size];
  +CharEntry[] tempccCache = new CharEntry[size];
   // Fill it up using an alphabetical order
   // and a dumb insert sort
   CharChunk tempChunk = new CharChunk();
  @@ -370,13 +371,13 @@
   for (int i = 0; i  list.size()  n  size; i++) {
   CharEntry entry = (CharEntry) list.get(i);
   tempChunk.setChars(entry.name, 0, 
entry.name.length);
  -int insertPos = findClosest(tempChunk, n);
  +int insertPos = findClosest(tempChunk, tempccCache, 
n);
   if (insertPos == n) {
  -ccCache[n + 1] = entry;
  +tempccCache[n + 1] = entry;
   } else {
  -System.arraycopy(ccCache, insertPos + 1, 
ccCache, 
  +System.arraycopy(tempccCache, insertPos + 1, 
tempccCache, 
   insertPos + 2, n - insertPos - 1);
  -ccCache[insertPos + 1] = entry;
  +tempccCache[insertPos + 1] = entry;
   }
   n++;
   }
  @@ -384,6 +385,7 @@
   }
   ccCount = 0;
   ccStats.clear();
  +ccCache = tempccCache;
   if (log.isDebugEnabled()) {
   long t2 = System.currentTimeMillis();
   log.debug(CharCache generation time:  + (t2 - t1) + 
ms);
  @@ -467,7 +469,7 @@
* Find an entry given its name in the cache and return the associated String.
*/
   protected static final String find(ByteChunk name) {
 

cvs commit: jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/buf StringCache.java CharChunk.java ByteChunk.java

2004-10-18 Thread remm
remm2004/10/18 16:16:36

  Modified:util/java/org/apache/tomcat/util/buf CharChunk.java
ByteChunk.java
  Added:   util/java/org/apache/tomcat/util/buf StringCache.java
  Log:
  - Refactor toString for the buffers, and add a cache.
  - The cache works in two phases:
- First phase is heavily synchronized, and keeps statistics on String usage
- When first phase is done (after a number of calls to toString), a cache array is 
generated; this might be a rather expensive operation
- During the second phase, unsynchronized lookups in the static cache are done to 
try to avoid expensive toString conversions
  - If the cache is registered in JMX (later ...), an operation exists to get back to 
the beginning of the first phase. This could be useful
after installing new applications on the fly, which could have different Strign 
requirements.
  - I think it works really well for ByteChunk - String, since this is a quite 
expensive operation (note: some of these conversions could
be optimized by assuming US-ASCII encoding, which I'll do for the session ID 
cookie value since it's so commonly used - and the String
is not cacheable, obviously - but doing the trick everywhere would lead to major 
problems). For CharChunk, it's less evident, as
it is a matter of allocating a String, a char array and then using an arraycopy to 
move over the chars.
  - This is configured using system properties, for example in the catalina.properties 
file. Byte and char can be enabled separately.
  
  Revision  ChangesPath
  1.16  +6 -0  
jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/buf/CharChunk.java
  
  Index: CharChunk.java
  ===
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/buf/CharChunk.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- CharChunk.java29 Aug 2004 17:14:41 -  1.15
  +++ CharChunk.java18 Oct 2004 23:16:36 -  1.16
  @@ -489,7 +489,13 @@
   //  Conversion and getters 
   
   public String toString() {
  +return StringCache.toString(this);
  +}
  +
  +public String toStringInternal() {
if( buff==null ) return null;
  +//System.out.println(CC toString:  + new String( buff, start, end-start));
  +//Thread.dumpStack();
return new String( buff, start, end-start);
   }
   
  
  
  
  1.22  +36 -22
jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/buf/ByteChunk.java
  
  Index: ByteChunk.java
  ===
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/buf/ByteChunk.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- ByteChunk.java29 Aug 2004 17:14:41 -  1.21
  +++ ByteChunk.java18 Oct 2004 23:16:36 -  1.22
  @@ -166,6 +166,11 @@
   public void setEncoding( String enc ) {
this.enc=enc;
   }
  +public String getEncoding() {
  +if (enc == null)
  +enc=DEFAULT_CHARACTER_ENCODING;
  +return enc;
  +}
   
   /**
* Returns the message bytes.
  @@ -448,28 +453,37 @@
   //  Conversion and getters 
   
   public String toString() {
  - if (null == buff) {
  - return null;
  - }
  - String strValue=null;
  - try {
  - if( enc==null ) enc=DEFAULT_CHARACTER_ENCODING;
  - return new String( buff, start, end-start, enc );
  - /*
  -   Does not improve the speed too much on most systems,
  -   it's safer to use the clasical new String().
  -
  -   Most overhead is in creating char[] and copying,
  -   the internal implementation of new String() is very close to
  -   what we do. The decoder is nice for large buffers and if
  -   we don't go to String ( so we can take advantage of reduced GC)
  -
  -   // Method is commented out, in:
  -   return B2CConverter.decodeString( enc );
  - */
  - } catch (java.io.IOException e) {
  - return null;  // XXX 
  - }
  +if (null == buff) {
  +return null;
  +} else if (end-start == 0) {
  +return ;
  +}
  +return StringCache.toString(this);
  +}
  +
  +public String toStringInternal() {
  +String strValue=null;
  +try {
  +if( enc==null ) enc=DEFAULT_CHARACTER_ENCODING;
  +strValue = new String( buff, start, end-start, enc );
  +/*
  + Does not improve the speed too much on most systems,
  + it's safer to use the clasical new String().
  + 
  + Most overhead is in creating char[] 

Re: cvs commit: jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/buf StringCache.java CharChunk.java ByteChunk.java

2004-10-18 Thread Remy Maucherat
[EMAIL PROTECTED] wrote:
remm2004/10/18 16:16:36
 Modified:util/java/org/apache/tomcat/util/buf CharChunk.java
   ByteChunk.java
 Added:   util/java/org/apache/tomcat/util/buf StringCache.java
 Log:
 - Refactor toString for the buffers, and add a cache.
 - The cache works in two phases:
   - First phase is heavily synchronized, and keeps statistics on String usage
   - When first phase is done (after a number of calls to toString), a cache array is generated; this might be a rather expensive operation
   - During the second phase, unsynchronized lookups in the static cache are done to try to avoid expensive toString conversions
 - If the cache is registered in JMX (later ...), an operation exists to get back to the beginning of the first phase. This could be useful
   after installing new applications on the fly, which could have different Strign requirements.
 - I think it works really well for ByteChunk - String, since this is a quite expensive operation (note: some of these conversions could
   be optimized by assuming US-ASCII encoding, which I'll do for the session ID cookie value since it's so commonly used - and the String
   is not cacheable, obviously - but doing the trick everywhere would lead to major problems). For CharChunk, it's less evident, as
   it is a matter of allocating a String, a char array and then using an arraycopy to move over the chars.
 - This is configured using system properties, for example in the catalina.properties file. Byte and char can be enabled separately.  

More optimizations:
- Optimize getting session id from the session id cookies: there might 
be more that one cookie, and all use straight byte - String conversion 
(although they are conversion friendly US-ASCII encoded); this will also 
avoid keeping track of too much stuff in the byte cache
- Enable the cache for ByteChunk by default (so that it gets tested, and 
optimizing away some of these expensive conversions could be quite useful)

Rémy
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]