views:

53

answers:

3

I'm having huge performance issues when I add RMI proxy references to a Java Swing JList-component.

I'm retrieving a list of user Profiles with RMI from a server. The retrieval itself takes just a second or so, so that's acceptable under the circumstances. However, when I try to add these proxies to a JList, with the help of a custom ListModel and a CellRenderer, it takes between 30-60 seconds to add about 180 objects. Since it is a list of users' names, it's preferrable to present them alphabetically.

The biggest performance hit is when I sort the elements as they get added to the ListModel. Since the list will always be sorted, I opted to use the built-in Collections.binarySearch() to find the correct position for the next element to be added, and the comparator uses two methods that are defined by the Profile interface, namely getFirstName() and getLastName().

Is there any way to speed this process up, or am I simply implementing it the wrong way? Or is this a "feature" of RMI? I'd really love to be able to cache some of the data of the remote objects locally, to minimize the remote method calls.


Update and possible solution: I created local classes that implements the remote interfaces and contains a reference to the remote objects. The speed enhancement is noticeable and it now works seemlessly (at least so far). I hope this works equally as well for the other interfaces we use in our application. Thanks for the input that I think helped guide me.

A: 

I think that you need to add the display fields to your Profile object and return them with the profile. Its fine to bring back the entire Profile in a single inspector view, but if you have them in an overview view you should bring them back in the initial query.

Justin
Not sure exactly what you mean by display fields and inspector view. The Profile class has the attributes firstName and lastName defined. The Objects themselves are mapped to a database with Hibernate.
Patrick
A: 

(a) It has nothing to do with RMI.

(b) Faffing around with binarySearch() is just wasting time. Sort the items first, or last, with Collections.sort(), or base your TreeModel on an intrinsically sorted collection.

EJP
It seems like either way I go - whether to presort the collection beforing adding them to the ListModel or use a sorted collection inside the ListModel, the performance is rather poor. I'm guessing it has to do with the comparator that makes two RMI calls to retrieve a profile's first and last names.
Patrick
Definitely. You should cache those, they will be called rather often during a sort, or a binarySearch().
EJP
+1  A: 

Patrick, are you calling Collections.binarySearch on Remote objects? It may be that you are inadvertantly causing a huge amount of traffic across the network if this method has to ask the rmi server for further information about the objects.

Finbarr