r/IPython • • Apr 02 '15

Memory issues with IPython notebook server

I have interest in using the IPython notebook server as a persistent place to store workflows, algorithms, and ideas. This seems like the perfect use-case for the notebook server - however, I'm having trouble wrapping my head around the server's memory usage. Currently, the server doesn't appear to manage memory well enough to support even a single working for a day or two.

I've turned off output caching and I'm avoiding "%matplotlib inline" (issue #7270 on Github).

To be clear, it's the notebook server running in Python3, that is growing in memory, not the kernel's. It appears that with every new notebook opened, the server allocates more memory, which makes sense. But closing and shutting down a notebook doesn't appear to free all of this memory. So as I close and open notebooks of varying sizes, the memory allocation grows and grows. Furthermore, the server will allocate more memory on the heap as the notebook produces output (which makes sense) and occasionally as some other operations occur (which is harder understand). But again, it seems that the server almost never frees memory, so eventually I cannot start any notebooks (I get memory allocation exceptions) and I'm eventaully forced to restart the server.

The notebook server is on a RHEL 6 machine, with 4GB of memory. I realizes this isn't much memory, but that doesn't explain why the notebook server can end up using GBs of heap with very little assets and after all kernels are stopped. I'm using the latest stable versions of both Python 2 and 3 compiled from source. I have the most experience with this problem using the PyPi version for Python3, but I've also confirmed this same problem in the repo's master branch (pulled ealier this week). The memory usage I'm referring to is the Proportional Set Size of the processes heap, found in /proc/<pid>/smaps.

Is an IPython notebook server meant to be "up" long-term? Or is are the notebooks intended to be just a niceity for spontaneous local work? Is this a known issue I'm not aware of? Is anyone else using the server in this way succesfully? Please let me know if there is any other information I can provide.

8 Upvotes

5 comments sorted by

View all comments

1

u/Berecursive Apr 03 '15

Are you actually having problems with the memory usage - as in, are you running out of memory (are called failing with OutOfMemoryError)? Because, if not, it's because IPython aggressively caches cell output in case you rerun a cell. In general, my notebooks appear to be using many GB of memory, but I never actually run out or hit swap unless I run a very memory hungry command.

1

u/Morgan243 Apr 03 '15

Yes, eventually any attempt to start a notebook results in an allocation exception from the interpreter.

1

u/Berecursive Apr 03 '15

Well, that definitely sounds like a bug on RHEL then!

2

u/Morgan243 Apr 03 '15

Though I didn't see any ulimits set, the administrator may have some other system memory limit set that I'm not aware of in order to avoid lockups (though it does have swap) - I'll be able to ask on Monday. These errors don't appear until the IPython notebook server, not kernel/notebook, has used over 80% of the memory with its heap.

Though I think this is missing my point - which is that the notebook server never appears to free memory. I know the server caches output, but when does it free this output? It seems irrational to prioritize the caching of non-volatile data in memory over the creation of new volatile data.

Perhaps the IPython notebook server simply requires more headroom, but if this is the case, it seems like poor design - especially considering its popularity in data rich environments.

Are you hosting a notebook server long-term?