i wonder if someone can provide some insight
on the garbage collection and heap size.

i wrote a program (below) in a loop
and recorded the response times and heap size.
when i started it, i was able to run the loop
125 times per second, using 11% CPU.  after several minutes,
i ran out of memory (default 16MB), and
my loop time was about 100 times every 6 seconds,
and the CPU was at 49%.


my questions are:
1.  why does performance go down so much when the heap size goes up?
     are we taking up lots of time sweeping through the heap?
2.  why does the jvm max out the heap when
     my objects are falling out of scope long before
     the maximum heap is reached.
3.  would it help to increase the max heap size (16MB), or
     is this just covering up another problem?

     public class test {

     public static void main(String[] args) throws Exception {
         int arg;
         long mem;
         arg = Integer.parseInt(args[0]);
         for (int i = 0; i < arg; i ++) {
             work(i);
         }
     }

     private static void work(int i) {
        try {
            if (i%100 == 0) {
                 Runtime rt = Runtime.getRuntime();
                 System.out.println(i + ":  " + rt.totalMemory() + " bytes\n");
             }
        URL yahoo = new URL("http://127.0.0.1/");
         URLConnection yc = yahoo.openConnection();
         BufferedReader in = new BufferedReader(
                                 new InputStreamReader(
                                 yc.getInputStream()));
         String inputLine;

         while ((inputLine = in.readLine()) != null)
             {}//System.out.println(inputLine);
         in.close();
        }
        catch(IOException e){
        }

     }



}


----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to