I have defined following 2 classes Person(with PersonKey) and Company() with companyId as key. PersonKey is affinity collocated with companyId. Now I am trying to do SQL distributed join (Person.companyId = Company.companyId) on 2 nodes connected in grid. I repeated same join with only single node. With distributed join in 2 nodes I should get 2x performance improvement, but it is performing worst with comparison to single node. Why is this happening? Are both nodes not participating in computation(here select query) part?
class PersonKey
{
// Person ID used to identify a person.
private int personId;
// Company ID which will be used for affinity.
@AffinityKeyMapped
private String companyId;
public PersonKey(int personId, String companyId)
{
this.personId = personId;
this.companyId = companyId;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((companyId == null) ? 0 : companyId.hashCode());
result = prime * result + personId;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
PersonKey other = (PersonKey) obj;
if (companyId == null) {
if (other.companyId != null)
return false;
} else if (!companyId.equals(other.companyId))
return false;
if (personId != other.personId)
return false;
return true;
}
}
class Person
{
@QuerySqlField(index = true)
int personId;
@QuerySqlField(index = true)
String companyId;
public Person(int personId, String companyId)
{
this.personId = personId;
this.companyId = companyId;
}
private PersonKey key;
public PersonKey key()
{
if(key == null)
key = new PersonKey(personId, companyId);
return key;
}
}
class Company
{
@QuerySqlField(index = true)
String companyId;
String company_name;
public Company(String CompanyId, String company_name)
{
this.companyId = CompanyId;
this.company_name = company_name;
}
public String key()
{
return companyId;
}
}