Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Very slow response with GWT RPC & Datasource

    SmartGWT version: 3.0

    Browser(s) version(s) involved:
    - Google Chrome: 14.0.835.202 m
    - Mozzila Firefox: v3.6.23

    Hi,

    I have a dataset of more than 2000 values (and this is one of the small ones I need to connect to) and I need to display them in a ListGrid. I have them in a list of objects, which contain fields: key & value (both Strings). I get these by doing an RPC call to my servlet from the client when I create my Datasoure and transform the objects to records and populate the Datasource. Here is my code:

    public class CacheKeysDS extends DataSource
    {
    private AdminServletAsync adminService = (AdminServletAsync) GWT.create(AdminServlet.class);

    public CacheKeysDS(String cacheName)
    {
    setClientOnly(true);
    DataSourceTextField key = new DataSourceTextField("key",
    "Key");
    key.setPrimaryKey(true);
    DataSourceTextField value = new DataSourceTextField("value",
    "Value");
    setFields(key, value);
    loadData(cacheName);
    }

    private void loadData(final String cacheName)
    {
    AsyncCallback<List<CacheKeys>> callback = new AsyncCallback<List<CacheKeys>>() {
    public void onFailure(Throwable caught) {
    System.out.println("Problem getting data from server");
    caught.printStackTrace();
    }
    public void onSuccess(List<CacheKeys> result) {
    // Map Part-Entities to ListGridRecords
    for (CacheKeys keys : result) {
    addData(new CacheKeysLGR(keys.getKey(), keys.getValue()));
    }
    }
    };
    adminService.getCacheKeys(cacheName, callback);
    }
    }

    I then call a fetch() command from my list grid and the data takes ages to load(more than 5mins) which is unacceptable.

    Now I tried flushing the data as JSON on my servlet and created a Datasource with a DSDataFormat.JSON format that gets the values from there just to compare the speed. Data gets loaded here quite quickly 5-10sec.

    The issue is I need to use the first approach because I need to push data from the server, which can be either a key's value has changed, a key has been added or a key has been deleted. I am doing this by using ICEPush and sending the objects to the client where I transform them in records and I perform correspondingly an updataData()/addData()/removeData() operation on the ListGrid. This works quite nice and is very fast.

    I tried using the JSON approach, and when I had a push event I was creating a JSONObject from the object pushed from the server. Then I created a Record from the JSON object with the following code:

    public class CacheKeysLGR extends ListGridRecord {
    public CacheKeysLGR() {

    }

    public CacheKeysLGR(JSONValue key, JSONValue value){
    setAttribute("key", key);
    setAttribute("value", value);
    }
    }

    Then I used the updataData()/addData()/removeData() operation on the ListGrid with the corresponding CacheKeysLGR record but the new data wasn’t picked up by my ListGrid.

    So am I doing something wrong and why is the response time so slow? If it is an issue with the RPC is there a way I can do this by using JSON?

    Thanks in advance!

    #2
    This slow conversion of objects is one of several major reasons we recommend against GWT-RPC (see FAQ). Stick with JSON, or better, use SmartGWT Pro+ (see QuickStart Guide chapter on Server Framework) which will allow you to delete a lot of server-side code that will no longer be necessary.

    If you want to use ICEPush to deliver dynamic updates, we have no particular experience with this product, but ultimately you will want to call DataSource.updateCaches(). When you instead call ListGrid.updateData() you are telling the system that you want to save a change to the server, which is not correct, what you're trying to do is update the local cache to reflect a change that's already been made. This is what updateCaches() does.

    Comment


      #3
      Hi,

      Again thanks for the quick reply. The updateCaches() didn't work for me, I think because I had my DataSource set to setClientOnly(true). Anyway I made it work with the following code:

      ListGrid.getDataSource().fetchData(null, new DSCallback() {
      public void execute(DSResponse response, Object rawData, DSRequest request) {
      ListGrid.getDataSource().updateData(updatedRecord);
      }
      });

      Comment


        #4
        updateCaches() should work with a clientOnly DataSource and your results suggest some kind of problem like not including the primaryKey in the update. However for a clientOnly DataSource it's fine to use updateData() since it doesn't trigger a server trip.

        Comment


          #5
          I did include the primary key, it was picking up updates, because I could see fields getting added to the list grid, but it wasn't displaying the data. Maybe I had something wrong somewhere... Don't know will double check it again.

          Comment

          Working...
          X