Skip to content

Cache all referenced resources (key to id) before reference resolution to improve performance.#574

Merged
ahmetoz merged 62 commits intomasterfrom
improve-cache-algorithm
Sep 25, 2020
Merged

Cache all referenced resources (key to id) before reference resolution to improve performance.#574
ahmetoz merged 62 commits intomasterfrom
improve-cache-algorithm

Conversation

@ahmetoz
Copy link
Copy Markdown
Contributor

@ahmetoz ahmetoz commented Sep 21, 2020

Improvement on the caching concept:

Currently, sync classes that doing reference resolution(for example ProductSync) only executes the cacheKeysToIds service methods to cache just for the draft resources (for example products for the ProductSync) but a resource could have other references (for example product type, tax category, state, and many others for ProductSync). And executing/syncing a batch of drafts the library is fetching one resource to find the id of the one reference.

We might improve the performance a lot of the library with iterating all references in a resource and collecting all referenced keys in a batch, then fetching together instead of fetching one by one during reference resolution (which is not good on the performance).

Assume a batch has 50 products, and 50 products will have 50 different custom object references, for this we will go 50 times into the commercetools. With the new design, we should aim at going only one time to collect all key to id mapping of the custom object.

Additionally, the BathProcessor concept is generalized as BaseBatchValidator for other sync processes, check the BaseBatchValidator class.

Relevant Issues

#235

Todo

  • Tests
    • Unit
    • Integration
  • Documentation
  • Add validator logic to all sync classes.
  • Add Release Notes entry.

salander85 and others added 23 commits September 8, 2020 12:55
Changes in CategoryBatchProcessor
* Rename to CategoryBatchValidator
* Handle errors inside
* Return a ImmutablePair of valid drafts and valid keys from the validation method
* Pass the batch of categoryDrafts in the validation method
* Change constructor to init syncOptions and statistics fields
…y-ref' into #235_improve-caching-for-category-ref
…y-ref' into #235_improve-caching-for-category-ref

# Conflicts:
#	src/main/java/com/commercetools/sync/categories/CategorySync.java
#	src/main/java/com/commercetools/sync/categories/helpers/CategoryBatchValidator.java
…y-ref' into #235_improve-caching-for-category-ref

# Conflicts:
#	src/main/java/com/commercetools/sync/services/impl/CategoryServiceImpl.java
#	src/test/java/com/commercetools/sync/categories/CategorySyncTest.java
…y-ref' into #235_improve-caching-for-category-ref
…or all batch helpers,

and create the concept for the caching improvement for the cacheKeyToId usages.
@ahmetoz ahmetoz changed the title Improve cache algorithm Cache all referenced resources (key to id) before reference resolution to improve performance. Sep 21, 2020
@ahmetoz ahmetoz marked this pull request as ready for review September 22, 2020 07:31
@ahmetoz ahmetoz changed the title Cache all referenced resources (key to id) before reference resolution to improve performance. WIP - Cache all referenced resources (key to id) before reference resolution to improve performance. Sep 22, 2020
@ahmetoz ahmetoz changed the base branch from #235_improve-caching-for-category-ref to master September 23, 2020 17:43
@ahmetoz ahmetoz changed the title WIP - Cache all referenced resources (key to id) before reference resolution to improve performance. Cache all referenced resources (key to id) before reference resolution to improve performance. Sep 24, 2020
Comment thread src/main/java/com/commercetools/sync/taxcategories/TaxCategorySync.java Outdated
Comment thread src/main/java/com/commercetools/sync/types/TypeSync.java Outdated
Comment thread src/main/java/com/commercetools/sync/types/TypeSync.java Outdated
@ahmetoz ahmetoz requested review from JudeNiroshan and removed request for butenkor and salander85 September 25, 2020 07:49
@Nonnull final ReferencedKeys referencedKeys,
@Nonnull final CategoryDraft categoryDraft) {

referencedKeys.categoryKeys.add(categoryDraft.getKey());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

it s still not removed

return syncBatch(validDrafts, keyToIdCache);
}

final Map<String, String> productKeyToIdCache = cachingResponse.getKey();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
final Map<String, String> productKeyToIdCache = cachingResponse.getKey();
final Map<String, String> productKeyToIdCaches = cachingResponse.getKey();

}

@Nonnull
private static Set<String> getReferencedKeysWithReferenceTypeId(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
private static Set<String> getReferencedKeysWithReferenceTypeId(
private static Set<String> getReferenceIdByReferenceTypeId(

* injected {@link io.sphere.sdk.client.SphereClient} and stores a mapping for every category to id in {@link Map}
* and returns this cached map.
* Filters out the keys which are already cached and fetches only the not-cached category keys from the CTP project
* defined in an injected {@link SphereClient} and stores a mapping for every category to id in the cached map of
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
* defined in an injected {@link SphereClient} and stores a mapping for every category to id in the cached map of
* d and stores a mapping for every category to id in the cached map of


/**
* Filters out the keys which are already cached and fetches only the not-cached customer group keys from the CTP
* project defined in an injected {@link SphereClient} and stores a mapping for every customer group to id in
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
* project defined in an injected {@link SphereClient} and stores a mapping for every customer group to id in
* } and stores a mapping for every customer group to id in

@ahmetoz ahmetoz merged commit ff8a981 into master Sep 25, 2020
@ahmetoz ahmetoz deleted the improve-cache-algorithm branch September 25, 2020 10:43
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.

5 participants