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

Schema Cache Improvements #5612

Merged
merged 17 commits into from
May 24, 2019
Merged

Schema Cache Improvements #5612

merged 17 commits into from
May 24, 2019

Conversation

dplewis
Copy link
Member

@dplewis dplewis commented May 23, 2019

Closes: #4530

Tested with Redis and enableSingleSchemaCache: true

Significant reduction on creating, updating and deleting objects.

Save 3000 objects with fix without reduction
number of calls 3301 6704 2x
  • Removed unnecessary clearing of the cache (multiple clears were chained)
  • Used one MAIN_SCHEMA instead of per class schema (reduce the number of lookups)

This can be further improved

  • schema.enforceFieldExist should be batched for multiple fields
    Could run in parallel instead of chained, should wait to refresh cache after all fields are checked. (Done)

  • schema.hasClass could check if class exists then reload if necessary
    This is a tricky one. Only used for allowClientCreation. AddClass and DeleteField clears the cache but maybe it should reload instead (This may come at a performance cost, I haven't done the research but up for discussion).

  • enableSingleSchemaCache should be true by default
    Tried and caused a few tests to fail. Will do a separate PR.

  • batch / saveAll / directAccess Adding class schema before batch will reduce calls in half if it doesn't exist. Adding batchSize > number of objects will result in fewer GET call but 4x as many PUT calls. (Need investigation)

@acinader
Copy link
Contributor

@davimacedo can you take a crack at reviewing?

@codecov
Copy link

codecov bot commented May 23, 2019

Codecov Report

Merging #5612 into master will increase coverage by 0.05%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5612      +/-   ##
==========================================
+ Coverage   94.06%   94.11%   +0.05%     
==========================================
  Files         129      129              
  Lines        9243     9231      -12     
==========================================
- Hits         8694     8688       -6     
+ Misses        549      543       -6
Impacted Files Coverage Δ
src/Controllers/DatabaseController.js 95% <ø> (-0.01%) ⬇️
src/Controllers/SchemaCache.js 100% <100%> (+11.62%) ⬆️
src/Controllers/SchemaController.js 97.1% <100%> (+0.7%) ⬆️
src/RestWrite.js 93.27% <0%> (-0.18%) ⬇️
...dapters/Storage/Postgres/PostgresStorageAdapter.js 96.81% <0%> (-0.09%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fe61f72...b4c4942. Read the comment docs.

@dplewis dplewis requested a review from davimacedo May 24, 2019 16:06
@dplewis
Copy link
Member Author

dplewis commented May 24, 2019

@acinader This is ready for review. I edit my original post with comments.

Copy link
Contributor

@acinader acinader left a comment

Choose a reason for hiding this comment

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

lgtm. i have a question on one of the tests.

spec/MongoStorageAdapter.spec.js Outdated Show resolved Hide resolved
spec/RedisCacheAdapter.spec.js Outdated Show resolved Hide resolved
@dplewis
Copy link
Member Author

dplewis commented May 24, 2019

@acinader I rewrote the tests and found more places for improvement. I'll post them up-for-grabs for the community.

Copy link
Contributor

@acinader acinader left a comment

Choose a reason for hiding this comment

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

real nice improvement in readability and quality in addition to the better performance.

I have one question about a test that is mystifying me. otherwise, this lgtm

spec/MongoStorageAdapter.spec.js Show resolved Hide resolved
spec/RedisCacheAdapter.spec.js Outdated Show resolved Hide resolved
@dplewis dplewis requested a review from acinader May 24, 2019 19:33
spec/Schema.spec.js Outdated Show resolved Hide resolved
return this._dbAdapter
.getAllClasses()
.then(allSchemas => allSchemas.map(injectDefaultSchema))
.then(allSchemas => {
Copy link
Member

Choose a reason for hiding this comment

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

It is a small improvement, but I think we don't need to wait the cache promise to resolve. I'd do something like this::

this._cache.setAllClasses(allSchemas).catch(error => console.error('Error saving schema to cache', error));
return allSchemas;

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree

Copy link
Member

@davimacedo davimacedo left a comment

Choose a reason for hiding this comment

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

I've just went through all changes and they seem all good to me. I think we are also well covered by the tests. It will bring great improvement for schema cache. LGTM!

@dplewis dplewis merged commit f7716f2 into master May 24, 2019
@dplewis dplewis deleted the schema-improvements branch May 24, 2019 21:42
UnderratedDev pushed a commit to UnderratedDev/parse-server that referenced this pull request Mar 21, 2020
* Cache Improvements

* improve tests

* more tests

* clean-up

* test with singlecache

* ensure indexes exists

* remove ALL_KEYS

* Add Insert Test

* enableSingleSchemaCache default true

* Revert "enableSingleSchemaCache default true"

This reverts commit 323e713.

* further optimization

* refactor enforceFieldExists

* coverage improvements

* improve tests

* remove flaky test

* cleanup

* Learned something new
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.

setOneSchema in SchemaCache is never triggered, many getOneSchema results in misses
3 participants