Issue type
Bug
How did you install PythonMonkey?
Installed from pip
OS platform and distribution
Ubuntu 22.04.4 LTS x86_64
Python version (python --version)
3.10.12
PythonMonkey version (pip show pythonmonkey)
0.8.0
Bug Description
I notice PythonMonkey will OOM in weird circumstances, and looking at ps -p $pid -o rss= , the rss memory usage (measured in kb) only hangs around the 200mb range (would be hilarious if I was off by a factor of 10 --- double check my work)
One thing to note, maybe this is expected? If it is, it would be sad - so hoping it's a bug!
Standalone code to reproduce the issue
#!/usr/bin/env python3
"""
Works at 1020000 elements, OOMs at 1030000 elements...
"""
import pythonmonkey as pm
oomer = pm.eval("""
function oomer()
{
let arr_size; // change array size to different values
arr_size = 1020000; // success!
arr_size = 1030000; // OOMs (ON MY SYSTEM! - maybe you'll have to up it to OOM on yours!)
const bigArray = [];
for (let i = 0; i < arr_size; i++)
bigArray.push(i + 0.1 / (i + 0.123456)); // randomish floats, fattened up by json.stringify A LOT later
//let seed = 1; bigArray.sort(() => (Math.sin(seed++) * 10000) % 1 - 0.5); // TODO unnecessary, remove later
// these initial values don't really matter per se, it's more just about how they're serialized
console.log(`Array length: ${bigArray.length}`);
console.log(`Array bytes : ${bigArray.length * 8}`); // 8 bytes per js number???
console.log(`Array MB : ${bigArray.length * 8 / 1000000}`);
// The following code is baed off of encodeJobValueList in dcp-client/job/index.js
const jsonedElementsArray = [];
for (let i = 0; i < bigArray.length; i++)
{
jsonedElementsArray.push(JSON.stringify(bigArray[i]));
// logging
if (i % 10000 === 0 && i > 600000) // skip first 600000 then only print every 10000 elements
console.log(i, ' -- ', bigArray[i]);
}
// now we calculate the total length of all the strings in the array and see how much memory they use
console.log(`JSONed Array length: ${jsonedElementsArray.length}`);
console.log(`JSONed Array bytes : ${jsonedElementsArray.reduce((acc, str) => acc + str.length, 0) * 2}`); // 2 bytes per character
console.log(`JSONed Array MB : ${jsonedElementsArray.reduce((acc, str) => acc + str.length, 0) * 2 / 1000000}`);
}
oomer
""")
oomer()
Relevant log output or backtrace
Traceback (most recent call last):
File "/home/will/git/oomy/./py-memory-bizarreness.py", line 63, in <module>
oomer()
pythonmonkey.SpiderMonkeyError: uncaught exception: out of memory
Additional info if applicable
I started this investigation when Dan reported an OOM during dcp job deploy for large job arguments, reproring that I found PythonMonkey would allocate more memory than nodejs and take far longer to execute the same amount of code
Refer to my slack messages:
- https://dstrbtv.slack.com/archives/C02FS7B9PCP/p1724702701635389
- https://dstrbtv.slack.com/archives/C02FS7B9PCP/p1724773152533229
---
Another similar issue is described here, it could be related! https://github.com/Distributive-Network/PythonMonkey/issues/420#issuecomment-2313497379
What branch of PythonMonkey were you developing on? (If applicable)
No response
Issue type
Bug
How did you install PythonMonkey?
Installed from pip
OS platform and distribution
Ubuntu 22.04.4 LTS x86_64
Python version (
python --version)3.10.12
PythonMonkey version (
pip show pythonmonkey)0.8.0
Bug Description
I notice PythonMonkey will OOM in weird circumstances, and looking at
ps -p $pid -o rss=, the rss memory usage (measured in kb) only hangs around the 200mb range (would be hilarious if I was off by a factor of 10 --- double check my work)One thing to note, maybe this is expected? If it is, it would be sad - so hoping it's a bug!
Standalone code to reproduce the issue
Relevant log output or backtrace
Additional info if applicable
What branch of PythonMonkey were you developing on? (If applicable)
No response