Skip to content

Commit

Permalink
[GraphQL] Use a sliding chunk size (#4599)
Browse files Browse the repository at this point in the history
Switches to using a chunk size of between 250 and 500 records. In cases where the page size is small (eg. 25 items) this will lead to a bit more memory usage but it greatly reduce the amount to round trips. As I/O is likely a bigger bottleneck than CPU or memory, this should greatly reduce resolver execution time.

Signed-off-by: James Phillips <jamesdphillips@gmail.com>
  • Loading branch information
jamesdphillips authored Feb 1, 2022
1 parent 8434028 commit 62baa2c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions backend/apid/graphql/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ const (
// entire keyspace.
maxCountNamespaceListEntities = 500

// The maximum page size the list resolver will use when fetching entities
// Range of applicable chunk sizes that will be used when retrieving entities
// from the store.
maxPageSizeNamespaceListEntities = 100
minChunkSizeNamespaceListEntities = 250
maxChunkSizeNamespaceListEntities = 500
)

var _ schema.NamespaceFieldResolvers = (*namespaceImpl)(nil)
Expand Down Expand Up @@ -253,11 +254,15 @@ func (r *namespaceImpl) Entities(p schema.NamespaceEntitiesFieldResolverParams)
res := newOffsetContainer(p.Args.Offset, p.Args.Limit)
ctx := store.NamespaceContext(p.Context, p.Source.(*corev2.Namespace).Name)

chunkSize := p.Args.Limit
chunkSize = maxInt(chunkSize, minChunkSizeNamespaceListEntities)
chunkSize = minInt(chunkSize, maxChunkSizeNamespaceListEntities)

ordering, desc := listEntitiesOrdering(p.Args.OrderBy)
pred := &store.SelectionPredicate{
Ordering: ordering,
Descending: desc,
Limit: int64(minInt(p.Args.Limit, maxPageSizeNamespaceListEntities)),
Limit: int64(chunkSize),
}

matches := 0
Expand Down

0 comments on commit 62baa2c

Please sign in to comment.