-
Notifications
You must be signed in to change notification settings - Fork 454
Open
Description
Profiling point queries using
var entity = ds.find(Entity.class).filter(eq("id", id)).first();shows that ~19 % of CPU time is spent caching codecs. When the query is repeated on the same datastore instance,
the cache is effectively emptied.
Flame graph of point query execution, highlighting the stack traces which show ineffective caching:
Root cause seems to be an undesired side-effect of re-setting codec registry on every query:
Datastore.find(Class<T>)callsDefaultQueryFactory.createQuery(Datastore, Class<T>, FindOptions, Document)- which uses the
MorphiaQuery(Datastore, Class<T>, FindOptions, Document)constructor to create a query - the constructor calls
Datastore.getCollection(Class<T>)to get a reference to the collection - which in turn calls MongoCollectionImpl.withCodecRegistry(CodecRegistry)
Result of this call chain is that the MongoDB driver creates a wrapped copy of the CodecRegistry with empty cache.
Not resetting the CodecRegistry on Datastore.getCollection(Class<T>) but instead making sure Morphia's CodecRegistry is always registered at database-level when Datastore is created restores codec cache effectiveness.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels