I'm new to looking into the Freenet code and haven't got the full picture of workflow, but I know it isn't pleasant.
The good news is I'm running with Windows ME MaxConnections set to 256 and freenet's max connections up to 128 without any additional bugs.


The squeamish should close their eyes now.

I've been trying out a profiler, seeing what it would pick up. It was counting waits so lead me to the following code.

BlockingQueue (the tabs are messed up in my changed version)
Half a dozen bugs and the potential to crash Java. You can't go blaming sun for the spec without a suitable alternative, (many have tried). See attached TimeTime.java for one of the unwritten limits of timing capability.


Irreversible - Not totally thread safe, but most will get away with it.

Lots of finals all over the place not making the slightest difference to performance.

Not fully following the next code I may not be correct, but here's what I see;

AbstractSelectorLoop register/unregister should be calling sel.wakeup().

AbstractSelectorLoop processWaiters that first while loop looks bad.

WSL/RSL beforeSelect - now why are these calling select?

WSL processconnections - currentJob.data - does this need synchronization? From what I can tell using limit is how the bandwidth limit is being set.
It's only set under one condition though: if(currentJob.data.remaining()>lim)
Then further down reverted back to it's old value.
So I have no idea how it's working.




package freenet.support;
import freenet.*;
import freenet.support.Logger;

import java.util.*;

/*
  This code is part of the Java Adaptive Network Client by Ian Clarke. 
  It is distributed under the GNU Public Licence (GPL) version 2.  See
  http://www.gnu.org/ for further details of the GPL.
*/

/**
 * Implements a thread-safe Blocking Queue. A BlockingQueue
 * is a FIFO (First In First Out) buffer
 * with the property that calls to dequeue() on an empty queue will block
 * until an element becomes available to dequeue.
 *
 * @author Scott G. Miller <[EMAIL PROTECTED]>
 */
public final class BlockingQueue {
    private LinkedList queue;

    /**
     * Construct an empty BlockingQueue.
     *
     *
     */
    
    public BlockingQueue() {
        queue=new LinkedList();
    }
    
    /**
     * Queues an object onto this BlockingQueue.
     *
     * @param o the object to enqueue
     */
    public void enqueue(Object o) {
        synchronized(queue) {
            assert o != null;
            queue.add(o);
            if (queue.size()==1)
                queue.notify();
        }
    }
    
    public Object dequeue() throws InterruptedException {
        return dequeue(-1);
    }
    
    /**
     * Dequeues an object from this BlockingQueue.  This method will return the
     * next element in this BlockingQueue, or block until one is available.
     *
     * @param millis maximum time in milliseconds to wait. -1 means wait forever
     * if necessary.
     * @return the object on the top of this BlockingQueue. null if it times out.
     * @throws InterruptedException if this thread is blocked in this method 
     * and something interrupts this thread.
     */
    public Object dequeue(int millis) throws InterruptedException {
                synchronized (queue) {
                        if (queue.isEmpty()) {
                                if (millis == -1) {
                                        while (queue.isEmpty())
                                                queue.wait();
                                } else {
                
                                        assert millis >=0 ;
                                        long stop = System.currentTimeMillis()+millis;
                                        long now;
                                        while (queue.isEmpty() && (now = 
System.currentTimeMillis()) > stop) {
                                                queue.wait(now-stop);
                                        }
                                        if (queue.isEmpty()) // timed out
                                                return null;
                                }
                        }
                        if (queue.size()>1)
                                queue.notify();
                        return queue.removeFirst();
                }
    }

    
    /**
     * Returns the empty status of this BlockingQueue.
     *
     * @return true if this BlockingQueue is empty, false otherwise.
     */
    public boolean isEmpty() {
        synchronized (queue) {
                        return queue.isEmpty();
        }
    }
    
    /**
     * Returns the number of objects in this BlockingQueue.
     *
     * @return the number of objects in this BlockingQueue.
     */
    public int size() {
                synchronized (queue) {
                        return queue.size();
                }
    }
}

class TimeTime {
        static int RESERVED = 10000;
        public static void main(String args[]) {
                StringBuffer content = new StringBuffer(RESERVED);
                int totalCount = 0;
                long totalTaken = 0;
                long start;
                long taken;
                try {
                        long startAll = System.currentTimeMillis();
                        for (int current = 1;current<=500;current++) {
                                totalCount += current;
                                start = System.currentTimeMillis();
                                // comment out this line to see how insignificant the 
other code is
                                Thread.sleep(current);
                                taken = System.currentTimeMillis() - start;
                                totalTaken += taken;
                                content.append(current + " " + taken + "\n");
                        }
                        taken = System.currentTimeMillis() - startAll;
                        if (content.length() > RESERVED);
                                System.err.println("Content: " + content.length() + ", 
reserved " +RESERVED);
                        System.out.println(content + "\n" + totalCount + " " + 
totalTaken);
                } catch (Exception e) {
                        System.out.println(e);
                }
        }
}
_______________________________________________
Devl mailing list
[EMAIL PROTECTED]
http://dodo.freenetproject.org/cgi-bin/mailman/listinfo/devl

Reply via email to