Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
FuelPHP success story: the tale about Kohana's memory leak
  • I have a huge website running on Kohana 3.1. A couple of days ago, I encountered a memory leak. After sleepless nights. I solved the problem. Here's the story: http://forum.kohanaframework.org/discussion/10720/memory-leak#Item_1 My problem now is how to transfer the codebase to FuelPHP -- or at least those that I know are memory extensive. :D
  • Although flattered I don't think this is going to be a quick fix for your problem. Zombor is actually right that the DB layer of FuelPHP 1.x is mainly the same as Kohana's. But the ORM is different, and so is the rest of the framework. As I don't see anything spectacular in your code, the main difference between this and something comparable in FuelPHP is the ORM call. Rewriting a full Kohana app to Fuel might be quite a bit of work, depending on the complexity of the app...
  • Harro Verton wrote on Saturday 5th of May 2012:
    Although flattered I don't think this is going to be a quick fix for your problem. Zombor is actually right that the DB layer of FuelPHP 1.x is mainly the same as Kohana's. But the ORM is different, and so is the rest of the framework. As I don't see anything spectacular in your code, the main difference between this and something comparable in FuelPHP is the ORM call. Rewriting a full Kohana app to Fuel might be quite a bit of work, depending on the complexity of the app...

    Rewriting the entire codebase of my app may be an exaggeration :D I can't do that, quite honestly. Took us a year now to have it done. I guess I'll just run the background workers and rewrite the codes in Fuel since these are the issues I've encountered with Kohana. My quick conclusion was, if the DB layer is same as Kohana, and I did not use the ORM module in this case, could it be that the leak on Kohana is coming from somewhere else? Like in the core?
  • Possible, I can't really comment on that. It is unlikely that the issue is in your piece of code, as you are constantly re-using everything in your loop. Memory leaks are usually very difficult to find, especially if this is a background process. You might be able to find something using an xdebug trace of the process, and analyse it with cachegrind. I personally never code endless loops. My background tasks process what there is to process, and then finish. If it needs to process a lot, I make it so that I can run the same process multiple times (using queues), and launch the processes from a queue manager (or if that is not there from cron every minute or so).
  • Harro Verton wrote on Sunday 6th of May 2012:
    Possible, I can't really comment on that. It is unlikely that the issue is in your piece of code, as you are constantly re-using everything in your loop. Memory leaks are usually very difficult to find, especially if this is a background process. You might be able to find something using an xdebug trace of the process, and analyse it with cachegrind. I personally never code endless loops. My background tasks process what there is to process, and then finish. If it needs to process a lot, I make it so that I can run the same process multiple times (using queues), and launch the processes from a queue manager (or if that is not there from cron every minute or so).

    Further into the investigation, I think it's Kohana's ORM is the culprit. Using plain DB class eliminates the leak. But when I use an ORM, the leak stays. Am I correct to assume that Fuel's ORM is different from Kohana's?
  • Yes, FuelPHP's ORM is written from scratch by Jelmer.
  • Further in my 'memory leak' investigation (as I continue to encounter problems with my code), here are some weird stuff I've encoutered: http://pastebin.com/c7pc5XjW This code is run on both Kohana and FuelPHP - identical, basic codebase, uses built in DB module, no ORM used, accessed the same Database. Fuel did not use oil. It was accessed through the public http the way Kohana was accessed. This code tries to process 50 records of about 10k records all in all. Here's my memory log for Kohana: http://pastebin.com/gUiF9D2w Here's my memory log for FuelPHP: http://pastebin.com/v8Pzwu77 Notice that Kohana started at 3Mb and ended at 7Mb. FuelPHP, however, started with around 11Mb, but ended with 11MB too. While Kohana started small, it looked to me that it does have a leak in this regard.
  • Interesting observation. But no closer to what's causing it. If you can run this interactively (i.e. through a browser request), you could record an xdebug trace and analyze it for memory usage through cachegrind.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion