I use Cherrypy in a RESTful web service, and the server returns XML as a result (lxml is used to create XML). Some of these XMLs are quite large. I noticed that memory is not freed after this request (which returns large XML) has been processed.
So, I highlighted the problem and created this very short dummy example:
import cherrypy
from lxml import etree
class Server:
@cherrypy.expose
def index(self):
foo = etree.Element('foo')
for i in range(200000):
bar = etree.SubElement(foo, 'bar')
bar1 = etree.SubElement(bar, 'bar1')
bar1.text = "this is bar1 text ({0})".format(i)
bar2 = etree.SubElement(bar, 'bar2')
bar2.text = "this is bar2 text ({0})".format(i)
bar3 = etree.SubElement(bar, 'bar3')
bar3.text = "this is bar3 text ({0})".format(i)
bar4 = etree.SubElement(bar, 'bar4')
bar4.text = "this is bar4 text ({0})".format(i)
bar5 = etree.SubElement(bar, 'bar5')
bar5.text = "this is bar5 text ({0})".format(i)
return etree.tostring(foo, pretty_print=True)
if __name__ == '__main__':
cherrypy.quickstart(Server())
After the request was made: http: // localhost: 8080 / index , memory consumption goes from 830 MB to 1.2 GB. Then, after the request has been processed, it drops to 1.1 GB and stays there until the server is disconnected. After shutting down the server, memory consumption drops to 830 MB.
() , , . ( ), 1,1 , . , , . - .
, ? .