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

lru_caches on the mapper classes are subtly wrong #1434

Closed
ml-evs opened this issue Dec 18, 2022 · 0 comments · Fixed by #1435
Closed

lru_caches on the mapper classes are subtly wrong #1434

ml-evs opened this issue Dec 18, 2022 · 0 comments · Fixed by #1435
Assignees
Labels
bug Something isn't working server Issues pertaining to the example server implementation

Comments

@ml-evs
Copy link
Member

ml-evs commented Dec 18, 2022

Turns out that lru_cache binds globally where it is defined, so the caches are shared between the different mapper types, e.g., adding a print inside the cached ENDPOINT method of the reference and structure mappers, you see the following behaviour:

>>> from optimade.server.mappers import ReferenceMapper, StructureMapper
>>> ReferenceMapper.ENDPOINT
recomputed for <class 'optimade.server.mappers.references.ReferenceMapper'>
'references'
>>> ReferenceMapper.ENDPOINT
'references'
>>> StructureMapper.ENDPOINT
recomputed for <class 'optimade.server.mappers.structures.StructureMapper'>
'structures'
>>> ReferenceMapper.ENDPOINT
recomputed for <class 'optimade.server.mappers.references.ReferenceMapper'>
'references'

i.e., since the maxsize on the cache is only 1, only successive calls to the same mapper are cached.

This behaviour is a bit unexpected and also be traced to various memory leaks; I don't think we need to worry about these specifically as we are not actually creating instances of the class (see this video for more info).

So, the simplest fix is just to increase the cache sizes so that each of the mapper caches can fit.

@ml-evs ml-evs added the bug Something isn't working label Dec 18, 2022
@ml-evs ml-evs self-assigned this Dec 18, 2022
@ml-evs ml-evs added the server Issues pertaining to the example server implementation label Dec 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working server Issues pertaining to the example server implementation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant