Archive for August, 2009


Tomcat performance monitoring..

Aug 27, 2009 in Java, Tomcat


  • 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


  • 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


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);
— */



Also, see
. . .

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=””>name</str>
<str name=””>0</str>
<str name=”f.text.hl.fragmenter”>regex</str>

— The alternate ‘nutch’ configuration is:


— 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 .