rishi007bansod
rishi007bansod

Reputation: 1469

Distributed SQL query performance in Apache Ignite

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;
    }
}

Upvotes: 1

Views: 412

Answers (1)

Valentin Kulichenko
Valentin Kulichenko

Reputation: 8390

Adding second node does not automatically mean that the query will become twice faster. Moreover, it can easily become slower because network is added, while in a single node deployment all the data is local.

To make the test more fair you can run a query from a client node [1] and change the number of server nodes. In this case the result set will be always sent across the network and you will see the real difference in performance with different number of servers.

[1] https://apacheignite.readme.io/docs/clients-vs-servers

Upvotes: 1

Related Questions