volroom

volroom

Hello, we’ve been investigating the performance of one of our queries - basically it’s used to list products and categories like you’d see on an e-commerce site. On our dev environment it takes roughly 10s, and with tracing I can see that the first ~2 seconds are spent fetching the main body of data (DB queries etc). Then at the end Absinthe.Phase.Document.Execution.Resolution takes up around 6 to 7s and Absinthe.Phase.Document.Result takes around 500ms.

We’re a bit surprised that the bulk of the request time is spent resolving the fields - in order to check that our resolvers aren’t the problem, we moved all the processing and logic into the context function, so that the fields are just resolved by Map.get/2

Is it just expected for the resolution phase to take this long? It is a big query to be fair (if I prettify the response it takes up 87,056 lines)

Showing Posts 1 to 5

FlyingNoodle

FlyingNoodle

I’m not an expert on absinthe or graphql but from my experience field resolution always takes the most time.

If I put an expensive operation in a field resolver it multiplies when resolving this field in 100 entities.

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Hey there @volroom to sanity check a few things here, you’re saying that all of the actual IO to load data has already been done?

Some additional context that would be helpful.

  1. How big is the query itself? Can you share it?

  2. How big is the result JSON (in bytes)

  3. Are you using the Persistent Term backend? This helps a lot with memory efficiency which can help.

volroom

volroom OP

Hi @benwilson512

Yes, we moved all IO & data wrangling right to the beginning.

Here’s the query for context:

query Categories($id: UUID, $slug: String, $fulfillmentDatetime: UTCTimestamp, $fulfillmentType: FulfillmentType) {
  store(id: $id, slug: $slug) {
    categories(
      fulfillmentDatetime: $fulfillmentDatetime
      fulfillmentType: $fulfillmentType
    ) {
      id
      name
      description
      products {
        id
        allergens
        calorieData {
          caloriesPerServing
        }
        defaultVariantId
        description
        images {
          original
          standard
          thumb
        }
        inStock
        limit
        dietaryRequirements
        modifierGroups {
          id
          name
          maximum
          minimum
          modifiers {
            id
            allergens
            image {
              original
              standard
              thumb
            }
            inStock
            name
            price {
              base
              discounted
              reduction
            }
            restrictions {
              alcoholic
            }
          }
        }
        name
        options {
          name
          values
        }
        pricing {
          lowestVariant {
            base
            discounted
            reduction
          }
          maximum {
            base
            discounted
            reduction
          }
          minimum {
            base
            discounted
            reduction
          }
        }
        promotion {
          amount
          discountType
        }
        quickAddAllowed
        seoDescription
        slug
        restrictions {
          alcoholic
        }
        variants {
          allergens
          id
          inStock
          name
          limit
          pricing {
            absolute {
              base
              discounted
              reduction
            }
            relative {
              base
              discounted
              reduction
            }
          }
          restrictions {
            alcoholic
          }
          options {
            name
            value
          }
        }
      }
    }
  }
}

Which returns an output of 3071.81KB

We aren’t using the Persistent Term backend, will give that a go.

Worth pointing out that the times I quoted in my OP are on a very CPU-constrained test environment, not production.

volroom

volroom OP

Persistent Term doesn’t seem to have had a significant impact

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

3 megs is a TON of data to ship via GraphQL. Unlike just shipping regular JSON every return value is type checked against the schema, errors are tracked at the node level, and so on. While there are hypothetical optimizations I have wanted to do in the resolution phase they’d involve a level of refactor I just haven’t had time for to date.

Overall I’d find a way to maybe paginate products if that’s the big field or something.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
ryanwinchester
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted” Version...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews