从 CFC 返回查询的内存影响
我在 ColdFusion 中编写了一个数据库加载脚本,但遇到了该脚本慢慢耗尽内存的问题。我已使用
我创建了一个 CFC 来保存脚本所需的所有查询。该脚本调用相应的 CFC 函数,该函数然后返回查询,其中一些查询大小超过 2 MB。当我在“活动线程的内存”页面的详细信息视图中查看“服务器监视器”时,看起来我的 CFC 正在内存中保留查询的副本,即使我对查询变量进行了 varscope 处理并且该变量最后超出了范围的函数。此外,我的线程内存中有查询的副本。所以我在内存中留下了看起来像查询的两个副本。这真的是发生的事情吗?如果是,如何从内存中消除该查询的一份副本?
I've written a database load script in ColdFusion and I'm having a problem that the script slowly runs out of memory. I've split each table load into its own thread with <cfthread> and I'm calling the garbage collector when memory dips below 50% (making sure to have 30 seconds between gc() calls to prevent the garbage collector from hogging memory).
I created a CFC to hold all the queries needed by the script. The script calls the appropriate CFC function which then returns the query, some of which are over 2 MB in size. When I look in the Server Monitor in the details view of the Memory page for Active Threads, it looks like my CFC is keeping a copy of the query in memory even though I varscoped the query variable and the variable went out of scope at the end of the function. In addition, I have a copy of the query in memory in my thread. So I'm left with what looks like two copies of the query in memory. Is this really what's happening? If it is, how can I eliminate one copy of the query from memory?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里有很多潜在的问题,但我将尝试强调一些需要您考虑的最重要的事情:
该查询可能会从您的 cfreturn 语句返回指向该查询的指针。在所有进程完成引用该查询之前,该查询不会被清除。因此,如果它将查询传递给其他进程,您将不会清除该查询的内存。例如,如果将该查询设置为会话变量,则无论您尝试强制垃圾回收的频率如何,该指针都不会移动到任何地方,直到该会话变量消失。
只需考虑几件事。
There's a lot of potential issues here, but I'll try to underline some of the most important things for you to consider:
The query is likely returning a pointer to the query from your cfreturn statement. That query will not be cleaned up until all processes are done referencing it. So if it passes the query to some other process, you're not going to get that query cleaned out of memory. If you set that query to a session variable, for instance, that pointer isn't going anywhere until that session variable is gone, no matter how frequently you try to force garbage collection.
Just a few things to consider.
我在处理大型数据插入时遇到了类似的问题,其中每一行都需要涉及多个 CFC 的大量处理。看来创建的 JDBC ResultSet、Statement 和 Connection 引用是正确的。一直保留到请求结束。这意味着将查询变量清空不会影响内存使用。我解决这个问题的方法是对 CFC 函数进行网关调用以处理 100 行,然后该函数对接下来的 100 行进行另一个网关调用,依此类推,直到处理完所有行。因为每个单独的网关调用实际上都会退出,所以它会释放所有句柄并恢复内存。
I had a similar problem with processing a large data insert, where each row requires extensive processing involving multiple CFCs. It appears that th JDBC ResultSet, Statement and Connection references created by <cfquery> are held until the end of the request. This means that nulling your query variable has no affect on memory usage. The way I got around this was to make a gateway call to a CFC function to processes 100 rows, then that function makes another gateway call for the next 100 rows etc until all rows are processed. Because each individual gateway call actually exits, it releases all it's handles and that memory gets recovered.