[jcifs] Fast cache access patch

Michael B Allen ioplex at gmail.com
Wed Feb 11 03:30:25 GMT 2009

On Tue, Feb 10, 2009 at 11:25 AM, Michael B Allen <ioplex at gmail.com> wrote:
> On Tue, Feb 10, 2009 at 7:12 AM, Jan Schlößin <jan.schloessin at klero.de> wrote:
>> Hello developers,
>> here comes a short patch for better name cache lookup throughput.
>> With this patch applied, my transfer runs _six_ times faster (many small
>> files with dozens of peers in parallel).
> I don't think this patch is thread-safe. But I'm not sure, it's been a
> while since I looked at that code. I've added it to the "TODO" for
> further reference if I ever touch that code again.
> Also, you might want to play around with the jcifs.resolveOrder
> property. If you're seeing long delays, it might just be name queries
> timing out.

Actually there's nothing wrong with the thread-safety of your patch.

However, the patch is invalid. The purpose of lookupServerOrWorkgroup
is to query the server and workgroup in parallel. So by calling
NbtAdress.getHostByName at the beginning, that effectively serializes
the lookups (and renders one of them redundant in the process). There
must be two threads to perform the lookups independently so that the
first to respond can signal the caller to return with the answer.

Again, I would look at the resolveOrder property to see if your
performance issue is actually name service lookup timeouts. Otherwise,
you're simply seeing the overhead of creating and running two threads.
But they are necessary since the client does not know if the target is
a server or workgroup.

You might also want to try fully qualified DNS names. If you use DNS,
I think this code might be bypassed entirely.


>> diff -Naur jcifs_1.3.3/src/jcifs/UniAddress.java jcifs_1.3.3_fast_cache/src/jcifs/UniAddress.java
>> --- jcifs_1.3.3/src/jcifs/UniAddress.java       2009-01-25 14:34:14.000000000 +0100
>> +++ jcifs_1.3.3_fast_cache/src/jcifs/UniAddress.java    2009-02-10 12:15:19.312500000 +0100
>> @@ -160,6 +160,12 @@
>>     static NbtAddress lookupServerOrWorkgroup( String name, InetAddress svr )
>>                                                     throws UnknownHostException {
>> +
>> +        // if the name is cached, don't wait for any pending lookup
>> +        // return immediately
>> +        NbtAddress na = NbtAddress.getByName(name);
>> +        if (na != null) return na;
>> +
>>         Sem sem = new Sem( 2 );
>>         int type = NbtAddress.isWINS( svr ) ? 0x1b : 0x1d;
> --
> Michael B Allen
> Java Active Directory Integration
> http://www.ioplex.com/

Michael B Allen
Java Active Directory Integration

More information about the jcifs mailing list