Hi,

Affinity collocation [1] should be used in cases when you need to perform JOINs 
between several tables or need to have data related to one cache to be near 
some other data from the second cache. AffinityKeyMapper is from this area. It 
shouldn’t affect the performance of your test. Read [1] to get basic 
understanding on this topic.

In your case since you’re testing queries over a single cache you can use 
“long” as a key and there is no need to use AffinityKeyMapper at all.

How big is your result set? Also make sure to warmup the JVM before storing 
measurements (you need to run the test for a minute or so and only after that 
start measuring the performance). Also it makes sense to execute the queries 
from several threads to see the difference since you want see significant 
difference if a query is executed from a single thread and there are 2, 4 or 5 
server nodes.

—
Denis

[1] https://apacheignite.readme.io/docs/affinity-collocation
> On Jul 6, 2016, at 12:24 PM, ght230 <[email protected]> wrote:
> 
> I had tested again using "AffinityMapper".
> 
> According to the result, It seems the effect of AffinityMapper is not very
> obvious.
> 
> Can you help me to confirm whether my test method is correct?
> 
> And can I observe that AffinityMapper has correctly setted from
> ignitevisorcmd?
> 
> Test result as following:
> **********************************************
> using AffinityMapper
> node(2) record number(300000)  query times(50000) TPS(10301)
> node(3) record number(300000)  query times(50000) TPS(10910)
> node(4) record number(300000)  query times(50000) TPS(10670)
> node(5) record number(300000)  query times(50000) TPS(11518)
> **********************************************
> Not using AffinityMapper
> node(2) record number(300000)  query times(50000) TPS(11908)
> node(3) record number(300000)  query times(50000) TPS(11699)
> node(4) record number(300000)  query times(50000) TPS(11893)
> node(5) record number(300000)  query times(50000) TPS(11011)
> 
> The test code as following:
> 
> public class Person2 implements Serializable {
> 
>       public Object ak;
> 
>       /** Person ID (indexed). */
>       @QuerySqlField(index = true)
>       public Long id;
> 
>       /** Organization ID (indexed). */
>       @QuerySqlField(index = true)
>       public Long orgId;
> 
>       /** First name (not-indexed). */
>       @QuerySqlField
>       public String firstName;
> 
>       /** Last name (not indexed). */
>       @QuerySqlField
>       public String lastName;
> 
>       /**
>        * Default constructor.
>        */
> 
>       public Person2() {
>               // No-op.
>       }
> 
>       public Object getAk() {
>               return ak;
>       }
> 
>       public void setAk(Object ak) {
>               this.ak = ak;
>       }
> 
>       public Long getId() {
>               return id;
>       }
> 
>       public void setId(Long id) {
>               this.id = id;
>       }
> 
>       public Long getOrgId() {
>               return orgId;
>       }
> 
>       public void setOrgId(Long orgId) {
>               this.orgId = orgId;
>       }
> 
>       public String getFirstName() {
>               return firstName;
>       }
> 
>       public void setFirstName(String firstName) {
>               this.firstName = firstName;
>       }
> 
>       public String getLastName() {
>               return lastName;
>       }
> 
>       public void setLastName(String lastName) {
>               this.lastName = lastName;
>       }
> 
>       public Person2(Object ak, Long id, Long orgId, String firstName, String
> lastName) {
>               super();
>               this.ak = ak;
>               this.id = id;
>               this.orgId = orgId;
>               this.firstName = firstName;
>               this.lastName = lastName;
>       }
> 
>       @Override
>       public String toString() {
>               return "Person2 [ak=" + ak + ", id=" + id + ", orgId=" + orgId 
> + ",
> firstName=" + firstName + ", lastName="
>                               + lastName + "]";
>       }
> 
> }
> 
> public class PersonKey {
> 
>       private Long id;
>       @AffinityKeyMapped
>       private Long orgId;
> 
>       public Long getId() {
>               return id;
>       }
> 
>       public void setId(Long id) {
>               this.id = id;
>       }
> 
>       public Long getOrgId() {
>               return orgId;
>       }
> 
>       public void setOrgId(Long orgId) {
>               this.orgId = orgId;
>       }
> 
>       public PersonKey(Long id, Long orgId) {
>               super();
>               this.id = id;
>               this.orgId = orgId;
>       }
> 
> }
> 
> public class Test3 {
> 
>       public static void main(String[] args) { 
>               // TODO Auto-generated method stub
> 
>               String personsCache = "personsCache";
> 
>               Ignition.setClientMode(true);
>               Ignite ignite = Ignition.start();
> 
>               CacheConfiguration<Object, Person2> cacheCfg = new
> CacheConfiguration<Object, Person2>(personsCache);
>               cacheCfg.setCacheMode(CacheMode.PARTITIONED);
>               cacheCfg.setIndexedTypes(Object.class, Person2.class);
> 
>               cacheCfg.setAffinityMapper(new AffinityKeyMapper() {
>                       @Override
>                       public Object affinityKey(Object key) {
>                               if (key instanceof PersonKey) {
>                                       PersonKey det = (PersonKey) key;
> 
>                                       return det.getOrgId();
>                               }
>                               return key;
>                       }
> 
>                       @Override
>                       public void reset() {
>                               // TODO Auto-generated method stub
> 
>                       }
>               });
> 
>               IgniteCache<Object, Person2> cachePerson =
> ignite.getOrCreateCache(cacheCfg);
> 
>               cachePerson.clear();
> 
>               int personId = 0;
>               int size = 10000;
>               int groupsize = 6;
> 
>               for (int gi = 0; gi < groupsize; gi++) {
>                       Long orgId = Long.valueOf(gi);
>                       for (int pi = gi * size; pi < (gi + 1) * size; pi++) {
>                               personId = pi;
>                               Object personKey1 = new 
> PersonKey(Long.valueOf(personId), orgId);
>                               Person2 p = new Person2(personKey1, 
> Long.valueOf(personId), orgId,
> "FN123", "LN456");
>                               cachePerson.put(personId, p);
>                       }
>               }
> 
>               SqlQuery sqlPer = new SqlQuery(Person2.class, "orgId=?");
> 
>               Long st = System.currentTimeMillis();
>               int cnt = 0;
>               Person2 rp = null;
>               try (QueryCursor<Entry&lt;Object, Person2>> cursor =
> cachePerson.query(sqlPer.setArgs("2"))) {
> 
>                       for (Entry<Object, Person2> e : cursor) {
>                               rp = e.getValue();
>                               cnt++;
>                       }
>                       System.out.println("return rownum:=" + cnt);
>               }
> 
>               cachePerson.clear();
>               cachePerson.destroy();
>               ignite.close();
> 
>       }
> 
> }
> 
> 
> 
> 
> --
> View this message in context: 
> http://apache-ignite-users.70518.x6.nabble.com/How-to-accelerate-the-query-speed-in-Partitioned-Mode-tp5826p6128.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Reply via email to