Archive for August, 2009

 

Tomcat performance monitoring..

Aug 27, 2009 in Java, Tomcat

From http://www.devx.com/Java/Article/32730

  • Tomcat Resource Pools.

    Connector Thread Pool

    Database Connection Pool

  • Use Tomcat Valves for implementing lightweight monitoring w/o JMX.

Hash table notes..

Aug 26, 2009 in Engineering, Java, JavaUsage, Software

From http://techinterviewcoach.com/blog/?p=30#more-30

  • Hash tables are backed by arrays.
  • A hash function is used to map the keys to an index within the backing array.
  • Put, Get, Delete operations all run in constant ( O(1) ) time.
  • Hash function determines performance.
  • Even with the best hash function, collisions can occur.
  • Main advantage of HTs over other data structures is speed.
  • Growing HTs need to be rehashed but the cost is amortized by constant cost of ‘put’.
  • Should not use HTs for small data sets, but everybody does.
  • Rehashing should occur when the load factor (occupied array slots / array size) reaches over .75.

Java example of basic cache (LRU) using LinkedHashMap ..

Aug 24, 2009 in Algorithms, Java, JavaUsage

From http://stackoverflow.com/questions/1229780/question-about-lru-cache-implementation-in-java

[java]
import java.util.Map;
import java.util.LinkedHashMap;

public class t1 {

final int MAX_ENTRIES = 2;

Map cache = new LinkedHashMap(MAX_ENTRIES+1, .75F, true) {
// This method is called just after a new entry has been added
public boolean removeEldestEntry(Map.Entry eldest) {
System.out.println(“eldest: ” + eldest.getKey() + “=” + eldest.getValue());
return size() > MAX_ENTRIES;
}
};

public void cacheAdd(String pkey, String pstr) {
// Add to cache
cache.put(pkey, pstr);
}

public static void main(String[] args) {
t1 ot1 = new t1();
ot1.cacheAdd(“k1”, “str1”);
ot1.cacheAdd(“k2”, “str2”);
ot1.cacheAdd(“k3”, “str3”);
ot1.cacheAdd(“k4”, “str4”);
}

/* —
// Get object
Object o = cache.get(key);
if (o == null && !cache.containsKey(key)) {
// Object not in cache. If null is not a possible value in the cache,
// the call to cache.contains(key) is not needed
}

// If the cache is to be used by multiple threads,
// the cache must be wrapped with code to synchronize the methods
cache = (Map)Collections.synchronizedMap(cache);
— */

}

[/java]

Also, see http://codeidol.com/java/javagenerics/Maps/Implementing-Map/
. . .

Solr integration with Nutch ..

Aug 20, 2009 in nutch, Search, solr

“requestHandler” notes for the solrconfig.xml file:

— Fields are defined here:

<str name=”hl.fl”>text features name</str>

— Field values are defined here:

<str name=”f.name.hl.alternateField”>name</str>
<str name=”f.name.hl.fragsize”>0</str>
<str name=”f.text.hl.fragmenter”>regex</str>

— The alternate ‘nutch’ configuration is:

(See http://www.lucidimagination.com/blog/2009/03/09/nutch-solr/)

— Fields:

<str name=”hl.fl”>title url content</str>

— Field values:

<str name=”f.content.hl.fragmenter”>regex</str>
<str name=”f.title.hl.alternateField”>title</str>
<str name=”f.title.hl.fragsize”>0</str>
<str name=”f.url.hl.alternateField”>url</str>
<str name=”f.url.hl.fragsize”>0</str>

— To map a parser to a file type,

— Map mime type for the file to a plugin in conf/parse-plugins.xml .

— Define new mime type for the file in conf/mime-types.xml .