RE: [Javagroups-development] Draw slow as molasses III
Brought to you by:
belaban
From: Filip H. <ma...@fi...> - 2002-02-26 23:05:50
|
>I thought about that too, but it seems not, see InetAddress source, the >getByName(String host) method. If the host is a String "%d.%d.%d.%d", like >it is the case with our IpAddress 1.4 serialized version then >cache is bypassed and simply new InetAddress is made. This is fine, but >hostname is never reseolved, unless you explicitely ask for resolving i.e >getHostName(). yeah, I wouldn't do it that way, instead in the Message class when you serialize the IpAddress, don't send over the IpAddress as a serialized object. Send over the string or the four bytes. When you deserialize the Message on the other end, you will simple set the instance variables to the cached values, kind of like this: public void writeExternal(ObjectOutput out) throws IOException { if (dest_addr != null) { out.writeBoolean(true); out.write(dest_addr.getBytes()); } else { out.writeBoolean(false); } ..... } public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { boolean destAddressExist = in.readBoolean(); if (destAddressExist) { //don't instantiate a new object at all!! byte[] mydest = new byte[4]; in.read(mydest); dest_addr = MyIpAddrCache.get(mydest); } .... } class MyIpAddrCache { static Map sAddressMap; public static IpAddress get(byte[] addr) { ...if the addr doesn't exist in the cache, simple create a new one and put the reference in the cache } } you see how I never instantiate a new object? the only problem with this is the setIpAddress(InetAddress) method, that would not be good since it is a shared reference. but I'm sure we can work around that Filip ~ Namaste - I bow to the divine in you ~ Filip Hanik Software Architect fi...@fi... www.filip.net >-----Original Message----- >From: jav...@li... >[mailto:jav...@li...]On Behalf Of >Vladimir Blagojevic >Sent: Tuesday, February 26, 2002 12:40 PM >To: jav...@li... >Subject: RE: [Javagroups-development] Draw slow as molasses III > > >Hey Filip, > >On Tue, 26 Feb 2002, Filip Hanik wrote: > >> Can you keep a cache of java.net.InetAddress in each static IpAddress >> instance? >> and when you deserialize v1.4 of IpAddress, get the actual >InetAddress from >> the cache. >> >> that way you will gain two things >> 1. The fabulous serialization speed that you have >> 2. No hostname look up since the cached instance of IpAddress will not do >> that. >> >> would that be possible? > > >I thought about that too, but it seems not, see InetAddress source, the >getByName(String host) method. If the host is a String "%d.%d.%d.%d", like >it is the case with our IpAddress 1.4 serialized version then >cache is bypassed and simply new InetAddress is made. This is fine, but >hostname is never reseolved, unless you explicitely ask for resolving i.e >getHostName(). > > >We could make our own cache in IpAddress, with "%d.%d.%d.%d" --> hostname >mapping or serialize an extra String hostname field we add in IpAddress >but this is no clean cut solutions. > >The last solution could for example in each explicit new >IpAddress() creation >save hostname in IpAddress instance field since it hits the InetAddress >underlying cache anyways. > >Bela and I disscussed this already but thought that it was stupid solutions >since it replicates InetAddress work. > >Vladimir > > > > > >_______________________________________________ >Javagroups-development mailing list > > |