Memory Effect on Request Return from CFC

I wrote a script database load in ColdFusion, and I had a problem with the script ending up slowly. I split each table load into its own thread using <cfthread> and I call the garbage collector when the memory drops below 50% (while you have 30 seconds between gc () calls to prevent garbage collection from the hogging memory).

I created CFC to store all the requests needed for the script. The script calls the corresponding CFC function, which then returns a request, some of which are larger than 2 MB. When I look in the "Server Monitor" in a detailed view of the "Memory" page for "Active threads", it looks like my CFC keeps a copy of the request in memory, although I varscoped in the request variable and the variable went out of scope at the end of the function. In addition, I have a copy of the request in memory in my stream. So I stayed with what looks like two copies of the request in memory. Is this really what is going on? If so, how can I delete one copy of the request from memory?

+6
coldfusion cfc
source share
2 answers

There are many potential problems here, but I will try to highlight some of the most important things you can consider:

  • Why streams? Do you need threads? There is a certain point at which you are probably redoing too much for your own good.
  • Manually forcing garbage collection is not necessarily a good idea. Configure the JVM to automatically collect garbage, but do not overdo it. Garbage collection tends to be expensive and can affect the performance of your application if it runs too often.
  • How do you create your CFC? If you create a CFC instance with every query request, you will experience RAM problems over time, slow memory leak, because CFCs load into RAM too quickly for garbage collection to continue. The best thing to do is singleton. (i.e. set it to the application area).
  • Keep in mind that the var-scoping variable of a variable (as I understand it) automatically frees up memory as soon as the variable is no longer used. The memory is still preserved, although it is probably marked somehow as part of a short-lived generation, so that it (probably?) Will be cleared faster. But this does not guarantee anything.
  • If you look at active threads, it is also possible that the request will not be cleared until the end of the request - not necessarily the end of the function call. It seems impatient to make you expect the request to die immediately as soon as the function call is complete.
  • ColdFusion requests are passed by reference , not by value. It is not possible to get 2 copies of a query in memory unless you somehow use duplicate () or a similar function to explicitly copy the query.

The request will most likely return a pointer to the request from your cfreturn statement. This request will not be cleared until all processes are made with its reference. Therefore, if it passes the request to another process, you are not going to clear this request from memory. If you specify this query for a session variable, for example, this pointer will not go anywhere until the session variable disappears, no matter how often you try to force garbage collection.

Just a few things to consider.

+11
source share

I had a similar problem with processing a large data insert, where each row requires extensive processing involving several CFCs. It seems that references to the JDBC ResultSet, Statement, and Connection created by <cfquery> are held until the end of the query. This means that resetting your query variable does not affect memory usage. The way I got around was to make a gateway call to the CFC function to process 100 lines, then this function makes another call to the gateway to the next 100 lines, etc., until all lines are processed. Since every single call to the gateway actually shuts down, it frees everything that it processes, and this memory is restored.

0
source share

All Articles