Partial Update

  Search Here
Searching XAP 6.0 Documentation

                                               

Summary: Updating only some of the fields of an object in the space.

Overview

In some cases you would like to update a specific Entry attribute without sending all Entry attributes to the space. The Partial Update mode allows you to call the update operation for specific Entry attributes without sending all Entry attributes through the network wire. This option is useful when the Entry includes large amount of attributes or when the Entry includes attributes with relatively large amount of data which does not need to be updated and few other attributes that do need to be modified.

This option is very useful for market data type applications when a stream of market data is sent where only a small amount of the stock object attributes need to be modified inside the space.

To use the PARTIAL_UPDATE mode you should first write your Entry with all its attributes into the space and later call the update operation using the PARTIAL_UPDATE modifier. The Entry itself should include a null value for all the Entry attributes you do not want to update.

space.update(entry, null, Lease.FOREVER, 0, UpdateModifiers.PARTIAL_UPDATE);

You can call the update operation without first reading the Entry, by using the Entry UID:

entry.__setEntryInfo(new EntryInfo(uid , 0));
entry.attribute1 = null;
entry.attribute2 = "NEW DATA";
space.update(entry, null, Lease.FOREVER, 0, UpdateModifiers.PARTIAL_UPDATE);

Since the update operation returns the previous version of the Entry, you might want to call the update operation without getting the existing entry stored at the space. To perform the update operation without getting the existing value, set the com.gs.onewayupdate system property to true:

System.setProperty("com.gs.onewayupdate","true");

When using this option, the return value from the update operation is null.
You should set the com.gs.onewayupdate to true before getting the space proxy.
Please note the com.gs.onewayupdate is not supported with transactional operations.

Data replication does not support partial update. All object attributes are replicated.

Example

The example below writes Entries with large payload attribute into the space, updates only one Entry attribute using the regular update operation, and later using the partial update mode to update only one Entry attribute value.

The difference in performance between the regular update and the partial update is measured.

package com.examples.partial_update;
import com.j_spaces.core.client.MetaDataEntry; 
public class PartialUpdateEntry extends MetaDataEntry {


                public PartialUpdateEntry() {
                }

                public String m_string = null;
                public Integer m_integer = null;

                public static String[] __getSpaceIndexedFields() {
                                String[] indexedFields = { "m_integer" };

                                return indexedFields;
                }
}
 
package com.examples.partial_update; 

import java.io.IOException;
import java.rmi.RemoteException;
import java.text.DecimalFormat; 

import net.jini.core.entry.UnusableEntryException;
import net.jini.core.lease.Lease;
import net.jini.core.transaction.TransactionException;
import com.j_spaces.core.IJSpace;
import com.j_spaces.core.client.SpaceFinder;
import com.j_spaces.core.client.UpdateModifiers;
 

public class Main {

                static IJSpace space = null;
                static int maxObjects = 10000;
                static DecimalFormat df = new DecimalFormat("#0.00");
                public void Main(){};
                public static void main(String[] args) {

                                try {
                                                System.out.println("Welcome to +	
                                                 GigaSpaces Partial Update Demo!");
                                                space = (IJSpace) SpaceFinder.find("rmi: +
                                                //localhost/./mySpace");
                                                if (space == null) {
                                                                System.out.println("Space not found: "
                                                                + args[0]);
                                                                System.exit(-1);
                                                }

                                                System.out.println("About to Clean Space...");
                                                space.clean();
                                                System.out.println
                                                ("Clean Space - OK!");
                                                new Main().go();
                                      // ////////////////////////////////////////////////////////////////
                                                ///////////////

                                } catch (Exception e) {

                                                e.printStackTrace();
                                } 

                } 

                public void go() throws TransactionException, UnusableEntryException,
                 InterruptedException, IOException

                {
                              

                            // 100 chars
                            StringBuffer data100Chars = new StringBuffer(
                                            "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                                             %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
                            StringBuffer dataStringBuffer = new StringBuffer();
                            for (int i = 0; i < 100; i++) {

                                            dataStringBuffer = dataStringBuffer.append(data100Chars);
                        }

                            String data = dataStringBuffer.toString();
                            long prev_time = System.currentTimeMillis();
                            long cur_time;
                            long duration;
                            PartialUpdateEntry entries[] = new PartialUpdateEntry[maxObjects];
                            long startTime = System.currentTimeMillis();
                            System.out.println("Payload size:" + data.length());
                            System.out.println("About Write " + maxObjects+ " entries to space");
                            for (int i = 0; i < maxObjects; i++) {

                                            entries[i] = new PartialUpdateEntry();
                                            entries[i].m_string = data;
                                            space.write(entries[i], null, Lease.FOREVER);
                                            if ((i % 1000 == 0) && (i > 0)) {

                                                            cur_time = System.currentTimeMillis();
                                                            duration = cur_time - prev_time;
                                                                System.out.println("Wrote " + i
                                                                                                + " entries
                                                                                                 to space
                                                                                                - Write TP:
                                                                                                " + df.format
                                                                                                (((double)
                                                                                                 1000 / (double)
                                                                                                  (duration ))
                                                                                                  * 1000)+
                                                                                                  " obj/sec" );
                                                                prev_time = cur_time;
                                                }

                                }

                                long endTime = System.currentTimeMillis();
                                System.out.println("Writing " + maxObjects + " entries to space...Done! - 
                                Write duration:
                                " + (endTime  -startTime) + " ms");
                                System.out.println("-------------------------------------------------------");
                                System.out.println("About to Update " + maxObjects+ 
                                " entries using Regular mode!");
                                System.setProperty("com.gs.onewayupdate","true");
 
                                long testTime = updateEntries(UpdateModifiers.UPDATE_ONLY, entries);
                                System.out.println("Done Update " + maxObjects+ " entries using Regular mode in 
                                " + testTime + " ms");
                                System.out.println("-------------------------------------------------------");

                                System.out.println("About to Update " + maxObjects  +
                                 " entries using PARTIAL UPDATE mode!");
                                testTime = updateEntries(UpdateModifiers.PARTIAL_UPDATE, entries);
                                System.out.println("Done Update " + maxObjects+ " entries using
                                 PARTIAL UPDATE mode in
                                 " + 
                                 testTime + " ms");
                                System.out.println("Click Enter to complete demo!");
                                System.in.read();
                                System.out.println("Done demo!");

                } 

                public long updateEntries(int updateMode, PartialUpdateEntry entries[])
                                                throws RemoteException, TransactionException,
                                                UnusableEntryException, InterruptedException {

                                System.out.println("-------------------------------------------------------");
                                long startTime = System.currentTimeMillis();
                                long prev_time = System.currentTimeMillis();
                                long cur_time;
                                long duration;

                                for (int i = 0; i < maxObjects; i++) {

                                                entries[i].m_integer = new Integer(i);
                                                if (updateMode == UpdateModifiers.PARTIAL_UPDATE)

                                                {

                                                                entries[i].m_string = null;
                                                }

                                                space.update(entries[i], null, Lease.FOREVER, 0, updateMode);
                                                if ((i % 1000 == 0) && (i > 0)) {

                                                                cur_time = System.currentTimeMillis();
                                                                duration = cur_time - prev_time;
                                                                System.out.println
                                                                ("Update " + i+ " entries in space - Update TP:"
                                                                +df.format
                                                                (((double) 1000
                                                                 / (double) (duration ))* 1000)+" obj/sec" );
                                                                prev_time = cur_time;
                                                }

                                }

                                long endTime = System.currentTimeMillis();
                                return (endTime - startTime);
                }

}

Expected output:

Welcome to GigaSpaces Partial Update Demo!
About to Clean Space...
Clean Space - OK!
Payload size:10000
About Write 10000 entries to space
Wrote 1000 entries to space - Write TP:463.61 obj/sec
Wrote 2000 entries to space - Write TP:551.88 obj/sec
Wrote 3000 entries to space - Write TP:592.42 obj/sec
Wrote 4000 entries to space - Write TP:410.34 obj/sec
Wrote 5000 entries to space - Write TP:528.82 obj/sec
Wrote 6000 entries to space - Write TP:507.87 obj/sec
Wrote 7000 entries to space - Write TP:547.05 obj/sec
Wrote 8000 entries to space - Write TP:603.86 obj/sec
Wrote 9000 entries to space - Write TP:633.71 obj/sec
Writing 10000 entries to space...Done! - 
Write duration:19031 ms
-------------------------------------------------------
About to Update 10000 entries using Regular mode!
-------------------------------------------------------
Update 1000 entries in space - Update TP:639.80 obj/sec
Update 2000 entries in space - Update TP:587.20 obj/sec
Update 3000 entries in space - Update TP:444.44 obj/sec
Update 4000 entries in space - Update TP:500.00 obj/sec
Update 5000 entries in space - Update TP:566.25 obj/sec
Update 6000 entries in space - Update TP:182.35 obj/sec
Update 7000 entries in space - Update TP:355.62 obj/sec
Update 8000 entries in space - Update TP:666.67 obj/sec
Update 9000 entries in space - Update TP:615.38 obj/sec
Done Update 10000 entries using Regular mode in 22360 ms
-------------------------------------------------------
About to Update 10000 entries using PARTIAL UPDATE mode!
-------------------------------------------------------
Update 1000 entries in space - Update TP:7142.86 obj/sec
Update 2000 entries in space - Update TP:7092.20 obj/sec
Update 3000 entries in space - Update TP:6410.26 obj/sec
Update 4000 entries in space - Update TP:2132.20 obj/sec
Update 5000 entries in space - Update TP:5347.59 obj/sec
Update 6000 entries in space - Update TP:4566.21 obj/sec
Update 7000 entries in space - Update TP:4926.11 obj/sec
Update 8000 entries in space - Update TP:4566.21 obj/sec
Update 9000 entries in space - Update TP:3759.40 obj/sec
Done Update 10000 entries using PARTIAL UPDATE mode in 2203 ms
Click Enter to complete demo!
Done demo!


GigaSpaces 6.0 Documentation Contents (Current Page in Bold)

    Java

    C++

    .NET

    Middleware Capabilities

    Configuration and Management

Add GigaSpaces wiki search to your browser search engines!
(works on Firefox 2 and Internet Explorer 7)

Labels