5.6 Advanced Characteristic

In order to improve the performance of the application, the View provides a serial of advanced characteristics, extends the concepts of the View, defines the concept of the field collecition, and implementing the data clipping. In the environment of the actual application, the network bandwidth could be largely saved through clipping data to prevent the network congestion. Whether the clipping could be implemented depends on the design of the logical function. For example, when using the data clipping, it is no need to dicuss the time sequence issue. So the application which requires the strict time sequence should not use the clipping.


  • The basic concept

    • Data collection

      The field information collection processed when the data sending opportunity of the View arrives.


    • Process collection

      The collection result is the all update history from the end of the last collection to the current time point. In the time scope of the two collections, how many times the same filed updates have the equal amount results. If the data of the two update has no change, the second update is simplified as a Touch.


    • Set collection (the basic mode of the Limax)

      The set collection is only applied to the process collection. The set collection aggregates the process collectors. The data each collected by the internal process collector combining with the process collector itself as a two-tuples is sequentially recorded. So the set collection could guarantee the update sequence of the collected fields.


    • Status collection (the extended mode of the Limax)

      The collection result is the last update result and all the previous datum are discarded. The field of the status collection is independent of the other fields, has no concept of the time sequence, and does not generate the Touch. In the precondition that the logical function allowes, compared with the process collection, the status collection could discard a mass of data and save the network bandwidth.


    • Immutable

      The immutable property, the Variable element described by the View corresponds to the filed with the immutable property, and the fields except for the map and set type defined by the Xbean which is referred by the Bind have the immutable property. These fileds could not be modified and only could be atomically replaced. The immutable filed only could use the immutable collector to collect data.


    • Mutable

      The mutable property, the Bind element described by the View corresponds to the field with the mutable property, and the fields of the map and set type defined by the Xbean which is referred by the Bind have the mutable property. These fields could be modified. For example, the map could directly execute the add/delete operation, however the reference of the map object itself has no change. The mutable field uses the mutable collector to collect data in most cases, and also could use the immutable collector to collect data in particular case. For example, even though the map could directly add/delete content, the entire replacement of reference is also allowed. The usage of the mutable property brings the possibility of the partial update of the data. It is benefical to save the network bindwidth when only sending the changed data. The Immutable and Mutable are automatically selected by the system according to the configure and the user does not need to intervene.


    • Tick

      The period of the field data collection, for the set collection, all the change in a period together with the sequence is collected; for the status collection, the last status is collected.


  • xml description extension


        <view name="TestTempView" lifecycle="temporary" tick="20">
            <variable name="var1" type="int" clip="true" />
            <bind name="bindfirst" table="roles" clip="true" snapshot="true" />
            <subscribe name="_var1" ref="gs.for_session.firstview.var1" snapshot=”true”/>
        </view>
    

    The tick attribute of the View element has no meaning to the global View. In the View element, the variable and bind elements provide two attributes, clip and snapshot; the subscribe field of the temporary View only provides the snapshot attribute.

    • tick attribute

      Configure the SessionView and the TemporaryView to generate the tick of the source code. The above configuration is 20, and the default value is 10ms. It could be modified through setTick in the program.


    • clip attribute

      Define the clip attribute, the protected boolean permitXXX(Type p) function will be generated in the _<ViewName>.java file in the gen directory, and the default return value is true.

      This function could be overrided in the <ViewName>.java file in the src directory, and returns true or false according to the requirement from the application.

      If returns false, the modification of the XXX field will be ingored.

      For example, a discardable data source is provided through View, the algorithm such as token-bucket could be used to control the traffic here.

      Different from the other View methods, the permitXXX method may not be called in the thread relative to the View. So the thread-safe problem should be considered when using this method. The input parameter could provides the reference for the filter, but could not be modifed and stored, except a copy.

      The description of the three kinds of View could apply the clip.

      In particular, if the Bind element defines the clip attribute, the generated source code will choose the Immuable collection mode, because in the Mutable mode, the partial update of the data is possible. If this update is discarded, the consistency of the data between the server and the client will be destroyed. For example, a Xbean includes A and B fields, the first time update A, and the second time update B. If the first update is discarded and the second update is sent to the client, the A filed in the client and the server is inconsistent in this case. However, only if the Immutable mode is used to process this Xbean to send all the data each time, even though the first update is discarded, the second update also includes all the previous update in this case.


    • snapshot attribute

      Declare this field as a status collection field, and associate to a status collector to be managed.

      For the global View, the setting of the snapshot has no meaning. The data send timepoint of the global View is determined by the user, and the latest data is sent. So the field of the global View uses the status collector. More, the partial update determined by the Mutable collection has no meaning to the field of the global View. Finally, all the field of the global view choose the Immutable status collector.

      The collection mode of the SessionView's field is irrelevant to the collection mode of the subscribed field of the corresponding temporary View. For example, TV._a subscribes SV.a, and there is no any problem for SV.a to use the process collection, and TV._a to use the status collection. In the implemention, the same updated data is provides to the each field collector of two View. The final output result is determined by the collector tand there is no any problem for SV.a to use the process collection, and TV._a to use the status collection


    • Collector selection

      1. For the SessionView and temporary View:

        Variable Bind Subscribe Subscribe/snapshot="true"
      Variable Bind Variable Bind
        PCS PCS PCS PCS ISC MSC
      napshot="true" ISC MSC PCS PCS ISC MSC
      clip="true" PCS PCS PCS PCS ISC ISC
      snapshot="true",clip="true" ISC ISC PCS PCS ISC ISC

      The first column expresses the attribute defined in the Variable/Bind. Tha last two Subscribe columns only has the meaning to the temporary View, and uses true/false to define the snapshot attribute to distinguish. Each member has a collector associated to the Subscribe in the temporary View.

      PCS:the set collector, the data added every time is queued.

      ISC:the Immutable status collector, when adding data every time, the new value is used to simply replace the previous one.

      MSC:the Mutable status collector, when adding data every time, the new value is merged to the previous one.

      The actual collection process: first read the PCS, then read the ISC/MSC one by one. For the subscribed field of the temporary View, the member who updates the subscribed field in this tick execute the above process one by one.


      2. All the fields of the global View use the ISC.


  • Large-scale data set broadcast

    • Global View extension

      A protected void onUpdate(String varname) method is provided; after overriding, it could know that some filed has changed. A syncToClient chance is provided here to send the data to the user.

      However, it should be paid attention is that the data sent by asynchronous trigger mode might not be the current updated data, but the lastest data. It is because that the operation on the global View is totally scheduled to the thread of the global View object itself. For example, the same field is continuely updated twice, and sent through onUpdate trigger, first setA then setB. The syncToClientA triggered by setA is placed behind the setB, so the sent data is B, and the syncToClientB triggered by B also sends the B. This example explains that the field of the global View is the status collection field from the other side.


    • Loose temporary View

      If the definition of the temporary View has no any subscription, the createLooseInstance() could be found in the generated source code. This method could create the loose temporary View. The loose temporary View will clip the Membership synchronization funtion of the standard temporary View. The broadcast perfomance could be improved and the network bindwidth will be reduced when operating the large-scale Membership.


      MyTemporaryView tview = MyTemporaryView.createLooseInstance();
      

      Seen from the server, there is no any difference between the loose temporary View and the standard temporay View.

      Seen from the client, the change of the Membership is clipped. So the empty sessionid list is imported when calling onOpen, and onAttach and onDetach methods are never be called.

      Just like the above example, the asynchronous global View broadcast should carefully control the time sequence, or the unexpected result might be generated. If it is synchronous and does not use the onUpdate, this kind of issue will not exist. For example, executing the sequence setA, syncToClientA, setB, syncToClientB, these four tasks will correctly be sorted to the global View thread. For the asynchronous mode and the correct sending sequence is required, it is a better choice to use the loose temporary View with the process collection mode for the relative sending field.

      In the status collection mode, the user controllability of the global View is higher. For the large-scale Membership set, the Membership could be divided to many segments, and the delay is inserted into each segment and sent one by one, which could effectvely prevent the network congestion.

      It should be considered from the design that the frequence of the large-scale set broadcast should not be too high, or the data total amount determines that the network congestion could not be avoided.


    • Partitional temporary View

      The createInstance(int partition) method could be found in the generated source code. If there is createLooseInstance(), the createLooseInstance(int partition) should exist at the same time.

      Partition the Membership by using the partition mode, the partition with the less member is always selected to accept the new member so that the partition member amount is relatively balanced. Each divison maintains a private data delivery queue.

      Each Tick processes a data collection, appends the data to the queue, refreshes the current partition queue, and finally switch the current partition to the next one.

      For the set collection, the collected data is apended to all the partition queues, and all the data will be sent to all the users just in different occasion.

      For the status collection, the collected data is just appended to the current partition queue. The status data obtained by each Tick is only sent to this partial user of the current partition.

      The normal temporary View is the special case of the partition temporary View with only one partition.

      For any user, the equivalent delay is tick * partition. If the design determines the longest acceptable Tick delay for each single user, the view.setTick(TICK/partition) should be called after creating the partition temporary View.

      Inferred from the theory, using the partition temporary View could reduce the burst network congestion.


    • Comparison

      1. The large-scale data set broadcast, when it needs to announce the member information, seen from the network load, the partition temporary View is always better than the standard temporay View. But the CPU and memory cost is bigger.

      2. The large-scale data set broadcast could make judgement according to the below table in the condition without announcing the member information.

        Global View Loose temporaryView Loose partition temporary View
      Process collection Bad, not suitable Medium Good
      Status collection Excellent, high controllbility Medium Good, automatic controll

  • Summary

    1. The snapshot/clip attributes could effectively cut down the data transmission, and reduce the bindwidth occupancy.

    2. The process collection needs to keep all the history data, and send when the tick arrives. So the tick delay is longer, the memory cost is larger.

    3. The Mutable status collection needs to keep all the history updated information, and merge and send when the tick arrives. So the tick delay is longer, the memory cost is larger and the burst CPU cost is larger.

    4. The Immutable status collection is the mode which saves memory and CPU cost most -- directly discards the previous data and has no merge requirement.

    5. For the Xbean with simple structure and small data, the side effect of the clip could be used to compulsively change the Bind field of the Mutable collection to the Immutable collection and reduce the expense of the CPU and the memory.

    6. Normally, the effective tick (tick*partition) determines the memory usage, the longer effective tick, the more memory usage; in the effective tick, the more partition, the more CPU expense -- partition process is required.

    7. In most case, only confirm that some field could accept the status data, through modifying the xml, setting the snapshot attribute, properly adjusting the tick, the performance could be effectively improved without modifying any code.


Prev Next