Home > Enterprise >  Why AppEngine can't load a big dictionary in its memory?
Why AppEngine can't load a big dictionary in its memory?

Time:07-13

I have a BFF service that reaches a microservice, and the second one pulls a long list from the DB, formats it and return the list to the BFF.

When I'm trying to run it through AppEngine I receive the following error:

Exceeded hard memory limit of 256 MB with XXX MB after servicing 0 requests total. Consider setting a larger instance class in app.yaml.

Where XXX is a different number each time, starting from 266 MB.

I tried to stop using pydantic (since it takes a lot of memory), to scale the instance to a huge machine, but the problem remains.

So I've copied the response (as I can run it locally) and copied it into the BFF (== skipping the whole microservice logic and store the response as a constant dictionary in the BFF).

And then, when the BFF has no logic besides loading a constant variable, I've received again the following error:

Exceeded hard memory limit of 256 MB with 919 MB after servicing 0 requests total. Consider setting a larger instance class in app.yaml.

The file that contains the data is a 9 MB file, the response that we create is around 3 MB, but it seems that the AppEngine can't really handle loading this dictionary to its memory in the BFF as well.

As there is no memory-profiling tool for AppEngine I'm not really sure what DOES take the memory and how can I make it work, any ideas?

Thank you!

CodePudding user response:

Apparently in python the dictionary size is also filled with metadata, and when the dictionary is big and has a complicated hierarchy - the size might raise exponentially.

That was the reason why a 9 MB data became a over 250 MB object in runtime.

  • Related