Monday, October 7, 2019

Space Object Model


Space Object Model


When constructing the space classes and their relationship, you should design the space classes to follow a few basic rules. The rules are mostly relevant when having associations between different objects, and when the database tables include foreign and primary key relations that need to be mapped to objects in memory.

There are two options you may use: a Hibernate-based model and a Space-based model.



The Space Object Model

Is the recommended one, since it provides better performance, scalability and consumes less memory when an object is stored in memory.


When you have an object graph object model with collections or references association (using Hibernate OneToMany, ManyToOne), you can use the Hibernate model to load these objects into the space. There are some important considerations when using this approach:
If you want to optimize the memory footprint, and avoid duplicated objects in memory, and the inconsistency involved with the usage of the Hibernate model when loading collection/reference objects, you need to implement the collection/reference object load and store, using the GigaSpaces API (at the DAO layer or some helper class). Important considerations when using this approach:
  • You can use the StatelessExternalDataSource that is usually faster than the DefaultExternalDataSource - but it does not support collection/reference load and store.
  • To load a collection/reference you should:
  1. Store the ID (and the routing data) of the parent object within the child object (in case we have a oneToMany relationship), to be able to fetch the collection. This ID field within the child object (of its parent object ID) should be indexed to allow fast data retrieval. The GigaSpace.readMultiple should be used to implement the relevant data access routine. In some cases it makes sense to implement such data access routines using the Task executors that allow you to implement multi-level object graph data retrieval without having multiple remote calls.
  2. Store the ID (and routing data) of the child object within the parent (in case of a OneToOne relationship). The GigaSpace.readById method should be used to implement the relevant data access routine.
  • The initial load phase runs faster than the Hibernate-based model.
  • Since each object loaded is a true space object, you have better control of how data is partitioned.
  • With this approach, the actual referenced object/collection within the space object is not stored within the space object. It should be excluded using the @SpaceExclude decoration. This allows the field data to be transient within the space object.

Ref: https://docs.gigaspaces.com/sbp/space-object-modeling.html#space-object-modeling

No comments:

Post a Comment

WebService, API and their Difference

Web service (WS) A service offered by an electronic device to another electronic device, communicating with each other via the World W...