CA
rare-sapphire

Get Memory Size From Input?

Currently, is there a way to determine the user's memory used without having them manually type it in? My program using multithreading (works better than async for my use case) and I want to automatically pick the optimal number of workers/threads based on the memory inputted. I tried multiprocessing.cpu_count(), but it seems to just respond with 16 every time. I viewed https://docs.apify.com/platform/actors/running/usage-and-resources but didn't seem to see it there I also noticed Lukas Krivka's message on 01/09/2023, but it seems to be more about handling it on the user side rather than developer: "Generally, if you know your total memory, you can just manage it locally completely but if you don't, you can use this API to get current value: https://api.apify.com/v2/users/me/limits?token=TOKEN. Just keep in mind that meanwhile some other task could have started if you don't have sole control over the account."
Usage and resources | Apify Documentation
Learn about your Actors' memory and processing power requirements, their relationship with Docker resources, minimum requirements for different use cases and its impact on the cost.
2 Replies
rare-sapphire
rare-sapphireOP3y ago
If anyone else has the same issue, I got it with this: (returning bytes) def get_memory_limit(): try: with open('/sys/fs/cgroup/memory/memory.limit_in_bytes') as f: return int(f.read()) except FileNotFoundError: with open('/sys/fs/cgroup/memory.max') as f: return int(f.read()) If anyone sees this though, please message if you know of a way to use the or operator for required? (I want user to be able to either enter usernames or search terms but have the flag raised without wasting compute it both are missing)
helpful-purple
helpful-purple3y ago
Just check the APIFY_MEMORY_MBYTES env var

Did you find this page helpful?