-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Cannot enlarge memory arrays #113
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
Comments
It would probably be best to build sql.js with |
Do you have any advice on how to do that? Rebuild that is. I tried setting the TOTAL_MEMORY but it's still ocurring |
Look for |
I had set oa=r.TOTAL_MEMORY||536870912 for 512MB, but you're saying the TOTAL_MEMORY var is possibly being set elsewhere, which makes my value unreachable right? |
Yes. |
Alright, thank you. Cmake wasn't playing ball so I was unable to compile with the ALLOW_MEMORY_GROWTH flag. Hopefully this sorts it out. |
Just a follow up on this (and thank you for your help BTW) My users are trying to load sql lite files that are ranging from 200MB to 4GB in size. Somewhere around the 2GB mark they're hitting "out of memory" and "invalid array buffer length" errors My exception reporting is showing this line for the invalid array buffer length issue
Do you think recompiling with ALLOW_MEMORY_GROWTH set would help? It seems the TOTAL_MEMORY config hasn't completely solved the problem |
JS engines probably won't let you allocate a 2GB typed array. In practice, in browsers even 512MB is unreliable due to memory fragmentation. |
Hmm, I was worried about that. So, would you say it's not going to be possible? |
Well 2GB should be possible in theory - the spec does not preclude it - but I just don't think you'll see it work in practice. Might be worth seeing if there are already bugs filed on this on browsers, likely there are. Also possible it works in some browsers but not others. Personally, I would guess that 2GB is unlikely to work, for now. Note that over 2GB would require a change to emscripten, as our pointers are 32-bit signed. |
It appears some people have been able to successfully load a 2GB file, although its rare. Most people say it crashes. Others say Safari seems to be more stable than Chrome and FireFox for loading the bigger files. I'm running out of ideas. |
I don't know about that question. The first issue is whether sqlite loads the entire file into memory. If it does, then yes - a full 2GB would be needed. If not, and sqlite instead reads slice by slice, then this might be done in emscripten, with some work. By default, when we preload a file, we do load it all into memory, and I think we use a typed array. But perhaps making us use a JS array instead would avoid that - if the browser can load a 2GB JS array, but not a 2GB typed array (which I don't know). The relevant code is in Another option might be to write a MEMFS alternative, that loads files in separate chunks. That still requires 2GB of memory, but not contiguous. I don't know how much that would help. Finally, avoiding 2GB entirely would require synchronous filesystem access - to load a chunk as it is needed, then free it. But the web doesn't have sync filesystem access. Web workers, however, do have synchronous Blob reading, so perhaps a solution could be done if the app runs in a worker. Overall, none of those options is easy to do, and all seem to have some risk. I'm afraid that loading 2GB+ files is just something browsers don't do well yet. Game engines and others have been complaining about this, so progress is being made, but it takes a while. As more browsers become 64-bit, that will help, for example. Perhaps you can work around this in some other way? Split up big sqlite databases? |
Thanks for the detailed explanation. Yes it sounds like none of those are easy to achieve. Unfortunately I can't control the files being loaded, these are from users machines, I just never expected them to be loading such large files. Regarding what we spoke about earlier, changing the TOTAL_MEMORY value, can you help me understand this a little better? What exactly is this setting a limit for? I set this to 256MB, does that mean the ceiling limit for loading these sql files into memory is 256MB? So, allocating 512MB would be more useful in my situation? |
TOTAL_MEMORY is the size of memory addressable by C. If a program tries to malloc enough that it requires more than that, it will fail (unless you build with memory growth). An application can use more memory than just the memory addressable by C. For example, files in the filesystem might be stored separately (there are some options there). |
I've got emscripten running on an Ubuntu 14.04 box. When you say " recompiling with ALLOW_MEMORY_GROWTH flag" can you expand on that a little? where do I set this? I installed using apt and im able to build the JS lib, im just not sure where that flag is. |
give emcc the extra args |
Getting there... I edited the Makefile, changed the optimized line to:
The build fails with: So, I edit the line again and added -s ASM_JS=0 and this time it finishes. The JS looks ok, but the browser throws an error when using it: The line looks minified, and not terribly useful, but the section is: [bc,za.Ha,za.Ec,za.Xa] I also noticed that the JS file is about 930Kb, which is smaller than the one in your repo. So im wondering what is missing. Any ideas? Looks like something is missing. Is there something else I should be doing rather than just editing this file and calling make ? |
What version of emscripten is that with? Disabling asm.js should break (with a clear error) on all recent versions. |
Doing install latest failed for me, with the following error although I was able build an earlier version (a stackoverflow suggestion)
On Ubuntu 14-04 |
1.10.0 is indeed quite old - I guess that's from the ubuntu repos? Stable is 1.34.0. I remember we had differences in how memory growth works in older versions, it used to disable asm.js. But that is no longer the case in recent versions. Not sure if that is the cause of your issues, but could be. Can try to build without closure and with |
Hi, I am trying to compile with this option as well thanks for this code, it's super useful for me, only need to get this memory option working and it would be perfect. |
Definitely cannot add |
Would it be possible to just add a compiled version of the latest sql.js with ALLOW_MEMORY_GROWTH bit set added to this repo ? or even just a once off that I can download from somewhere? I’m not 100% sure it’s going to solve my problem, and I've wasted enough of your time trying to get my build environment up and running. I appreciate the help, I don’t want to keep bugging you though. |
I compiled with adding only https://raw.githubusercontent.com/lpantano/seqclusterViz/master/js/sql.js thanks for the help! |
Thanks @lpantano! |
yes, it is. I compiled and pushed to the repo is using sql.js hope you have the same luck! |
Thanks @lpantano , you just saved me a few hours of hassle :) |
Yes, good idea! It's not the first time someone comes up with this problem, and not everyone has the courage to build SQL.js on his own. Le 21 juillet 2015 02:59:15 GMT+02:00, Alon Zakai notifications@github.com a écrit :
|
I'm getting horrible insert throughput, like only 100/s. Does this sound right? |
Please open a new issue, and give more details. |
… for everyone, keep it up to date as part of releases Closes sql-js#113
This should fix the occasional problems I was getting with memory usage when keeping a database open for a while. See https://github.com/kripken/sql.js/issues/113 for more info on how/why this works. I doubt this will be a cure-all solution, but it should at least rectify some of our prior problems.
For those googling the Append Substitute |
@duffrind this raised error "'Module' is not defined" |
Hi there
I'm getting tonnes of:
Cannot enlarge memory arrays. Either (1) compile with -s TOTAL_MEMORY=X with X higher than the current value 16777216, (2) compile with ALLOW_MEMORY_GROWTH which adjusts the size at runtime but prevents some optimizations, or (3) set Module.TOTAL_MEMORY before the program runs.
Is there a way to increase the allowed memory? The memory keeps blowing out for me.
Running in browser, client side
The text was updated successfully, but these errors were encountered: