Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved search performance #3326

Merged
merged 6 commits into from
Oct 18, 2023
Merged

Conversation

valentinyanakiev
Copy link
Member

@valentinyanakiev valentinyanakiev commented Oct 17, 2023

I have put performance counters to evaluate where the huge performance degradation of the search is coming from. To put it into context:

  • Doing a search with the query below takes about 2 seconds on prod and about 90 locally.
query search($searchData: SearchInput!) {
  search(searchData: $searchData) {
    journeyResults {
      id
      score
      terms
      type
      ... on SearchResultSpace {
        ...SearchResultSpace
        __typename
      }
      ... on SearchResultChallenge {
        ...SearchResultChallenge
        __typename
      }
      ... on SearchResultOpportunity {
        ...SearchResultOpportunity
        __typename
      }
      __typename
    }
    journeyResultsCount
    contributorResults {
      id
      score
      terms
      type
      ... on SearchResultUser {
        ...SearchResultUser
        __typename
      }
      ... on SearchResultOrganization {
        ...SearchResultOrganization
        __typename
      }
      __typename
    }
    contributorResultsCount
    contributionResults {
      id
      score
      terms
      type
      ... on SearchResultPost {
        ...SearchResultPost
        __typename
      }
      __typename
    }
    contributionResultsCount
    __typename
  }
}

fragment SearchResultSpace on SearchResultSpace {
  space {
    id
    nameID
    profile {
      id
      displayName
      tagset {
        ...TagsetDetails
        __typename
      }
      tagline
      visuals {
        ...VisualUri
        __typename
      }
      __typename
    }
    context {
      id
      vision
      __typename
    }
    authorization {
      id
      anonymousReadAccess
      __typename
    }
    community {
      id
      myMembershipStatus
      __typename
    }
    visibility
    __typename
  }
  __typename
}

fragment TagsetDetails on Tagset {
  id
  name
  tags
  allowedValues
  type
  __typename
}

fragment VisualUri on Visual {
  id
  uri
  name
  __typename
}

fragment SearchResultChallenge on SearchResultChallenge {
  challenge {
    id
    nameID
    profile {
      id
      displayName
      tagset {
        ...TagsetDetails
        __typename
      }
      tagline
      visuals {
        ...VisualUri
        __typename
      }
      __typename
    }
    spaceID
    context {
      id
      vision
      __typename
    }
    authorization {
      id
      anonymousReadAccess
      __typename
    }
    community {
      id
      myMembershipStatus
      __typename
    }
    __typename
    opportunities {
      id
    }
  }
  space {
    id
    nameID
    profile {
      id
      displayName
      tagline
      __typename
    }
    authorization {
      id
      anonymousReadAccess
      __typename
    }
    visibility
    __typename
  }
  __typename
}

fragment SearchResultOpportunity on SearchResultOpportunity {
  opportunity {
    id
    nameID
    profile {
      id
      displayName
      tagset {
        ...TagsetDetails
        __typename
      }
      tagline
      visuals {
        ...VisualUri
        __typename
      }
      __typename
    }
    context {
      id
      vision
      __typename
    }
    authorization {
      id
      anonymousReadAccess
      __typename
    }
    community {
      id
      myMembershipStatus
      __typename
    }
    __typename
  }
  challenge {
    id
    nameID
    profile {
      id
      displayName
      __typename
    }
    authorization {
      id
      anonymousReadAccess
      __typename
    }
    __typename
  }
  space {
    id
    nameID
    profile {
      id
      displayName
      __typename
    }
    visibility
    __typename
  }
  __typename
}

fragment SearchResultUser on SearchResultUser {
  user {
    id
    nameID
    profile {
      displayName
      ...SearchResultProfile
      __typename
    }
    __typename
  }
  __typename
}

fragment SearchResultProfile on Profile {
  id
  description
  location {
    id
    country
    city
    __typename
  }
  tagsets {
    ...TagsetDetails
    __typename
  }
  visual(type: AVATAR) {
    ...VisualUri
    __typename
  }
  __typename
}

fragment SearchResultOrganization on SearchResultOrganization {
  organization {
    id
    nameID
    profile {
      displayName
      ...SearchResultProfile
      __typename
    }
    __typename
  }
  __typename
}

fragment SearchResultPost on SearchResultPost {
  post {
    id
    nameID
    profile {
      displayName
      visual(type: CARD) {
        ...VisualUri
        __typename
      }
      ...SearchResultPostProfile
      __typename
    }
    createdBy {
      id
      profile {
        id
        displayName
        __typename
      }
      __typename
    }
    createdDate
    comments {
      id
      messagesCount
      __typename
    }
    __typename
  }
  ...PostParent
  __typename
}

fragment SearchResultPostProfile on Profile {
  id
  description
  tagset {
    ...TagsetDetails
    __typename
  }
  __typename
}

fragment PostParent on SearchResultPost {
  space {
    id
    nameID
    profile {
      id
      displayName
      __typename
    }
    authorization {
      id
      anonymousReadAccess
      __typename
    }
    __typename
  }
  challenge {
    id
    nameID
    profile {
      id
      displayName
      __typename
    }
    authorization {
      id
      anonymousReadAccess
      __typename
    }
    __typename
  }
  opportunity {
    id
    nameID
    profile {
      id
      displayName
      __typename
    }
    authorization {
      id
      anonymousReadAccess
      __typename
    }
    __typename
  }
  callout {
    id
    nameID
    framing {
      profile {
        id
        displayName
        __typename
      }
      __typename
    }
    __typename
  }
  __typename
}
{
  "searchData": {
    "terms": [
      "Energy"
    ],
    "tagsetNames": [
      "skills",
      "keywords"
    ],
    "typesFilter": [
      "space",
      "opportunity",
      "challenge",
      "post",
      "user",
      "organization"
    ]
  }
}

After putting performance counters pretty much everywhere, the problem was located in the Journey queries. I believe simply the ORM builds too big / slow of a queries after the latest changes and the environment can barely handle them. It took ~30 seconds (+-5) for each of searchSpacesByTerms, searchChallengesByTerms, searchOpportunitiesByTerms.
I have tried the following:

  • removing redundant .leftJoinAndSelect - helped marginally
  • replacing .leftJoinAndSelect with .leftJon and Select separately - almost didn't help at all
  • counter-intuitively, querying more data and manipulating in-memory instead of in the DB - that worked the best

I have optimized the performance an order of magnitude, but the starting point is really suboptimal. Getting from ~90 to 8-10 sounds great only in theory - it's still too slow, but I am not sure what can be done with our technology choices in short space of time.

@techsmyth - this needs a discussion asap.

techsmyth
techsmyth previously approved these changes Oct 18, 2023
Copy link
Member

@techsmyth techsmyth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code itself looks fine, but it seems odd that doing it in the server is faster than doing it at the database level. If it is needed for the release just go, we know that we medium term need to get onto elastic for searching anyway...

@valentinyanakiev valentinyanakiev marked this pull request as ready for review October 18, 2023 10:17
@valentinyanakiev valentinyanakiev merged commit 6c8ef81 into develop Oct 18, 2023
2 checks passed
@valentinyanakiev valentinyanakiev deleted the fix-search-performance branch October 18, 2023 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants