Avoid the Pitfall of node_load_multiple API Function

In a large website with many nodes, stop using the node_load_multiple function. It potentially limits the site growing.

According to the document: "This function should be used whenever you need to load more than one node from the database." But, I want to say that we should avoid using this function as this open the door to system crash in the future.

I had written a blog before Design a Drupal website with a million nodes in mind. I had used this function as an example. It is true that node_load_multiple function enhance the performance. But, it comes with a price. When we load thousands of node into the memory, it exhausts the web server memory instantly. Then we get this infamous message: "Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate XYZ bytes) in ...".

This issue brought me to an attention when I am reading the code done by one of the Drupal shops. In one of the recently launched high-profile project, the function is used to load all the show nodes in the system. It sounds to be troublesome to me at the beginning. We can not load all show nodes if we are not sure how many it will be? Where there are a small amount of node in the system, that is fine. But if it is for a system there are over hundred thousand nodes, that is a big problem. As time goes by, we add more shows into the system; The utility function needs more memory to handle it. The physical memory limits the ability to add infinity show nodes into the system.

What is the best way to handle this situation? Avoid using the node_load_multiple function. If we have to use the node_load_multiple, limit the number of the node for node_load_multiple to load.


Still has uses

I think it would be rare case where you would be using this function to load all the nodes in a system. Yes, that would not be good to use it for that. But there will be a lot of cases even in sites with thousands of node where you would use this function to load a limited number of nodes. If there is a situation where you have to load all the nodes on a site there are probably other problems with your code.

Avoid using node_load_multiple() ... what?

This article is pretty much wrong. It would be much more instructive to write about node_load_multiple() (or node_load() for that matter) being an expensive operation, and how to recognize and avoid usage that would cause scalability issues.


Avoid loading more data into memory than memory you have. That's a tautology. node_load_multiple() is incredibly useful and you should use it.

A slippy slope to the scalability issue

It is a slippy slope to the scalability issue. I think it worthwhile to bring attention to other developers. Will not waste time on it if I did not see this issue in our code and even a contributed module.

Saying not to use node_load

Saying not to use node_load_multiple because it would allow you to crash your site is like saying you shouldn't use PHP because it is not strongly typed. In both cases it's up to the developer to make good choices for their target system and blaming the tool for poor decisions made be the wielder of the tool is foolish.

Of course you should use node

Of course you should use node_load_multiple if you need to load multiple nodes. It's just a matter of passing in the nids you want. The title of the article is confusing at best and the article doesn't do a good job explaining the actual problem(loading all the nodes in the system). To be also honest, I have not seen anyone actually using this function to load all the nodes on the site without passing nids...that can indeed be irresponsible at times.

Always ask why

Why do you need to load all nodes? To get a field value? Use my sandbox project to do that: https://www.drupal.org/sandbox/mikeytown2/2209909 Every tool can be misused.

Yes it is bad

Yes doing node_load_multiple() is bad. But doing node_load_multiple(array(nids...)) is no problem at all. That's the reason the function utilizes not only an array of nids, but also conditions. If someone is loading all the nodes on a site in a single page request, then they are doing it wrong.

Yukiko spoke to me again as if I could not control his emotions.

Yukiko spoke to me again as if I could not control his emotions. http://xn--o80b910a26eepc81il5g.zxc700.com - 카지노사이트 http://xn--c79a67g3zy6dt4w.zxc700.com - 카지노검증사이트 http://xn--oi2b43dh5aa317l40j.zxc700.com - 모바일바카라 http://xn--oi2b30g3ueowi6mjktg.zxc700.com - 바카라사이트 http://xn--oi2ba146a24mbtbtvt.zxc700.com - 온라인바카라 http://xn--o80bz00bbzcu6f.zxc700.com - 샌즈카지노 http://xn--oi2b30ghxt.zxc700.com - 바카라 http://xn--on3b21eb4bmwh91q.zxc700.com - 바카라주소 http://xn--mp2bs6av7jp7brh74w2jv.zxc700.com - 슬롯머신사이트

Because consumers have changed.

Because consumers have changed. http://xn--oi2ba146a24mbtbtvt.vom77.com - 온라인바카라 http://xn--o80b910a26eepc81il5g.vom77.com - 카지노사이트 http://xn--o80b67oh5az7z4wcn0j.vom77.com - 모바일카지노 http://xn--mp2bs6av7jp7brh74w2jv.vom77.com - 슬롯머신사이트 http://xn--o80b27i69npibp5en0j.vom77.com - 온라인카지노 http://xn--vf4b27jfzgc8d5ub.vom77.com - 포커사이트 http://xn--7m2b7ov9poqh97o.vom77.com - 룰렛사이트 http://xn--oi2b30g3ueowi6mjktg.vom77.com - 바카라사이트 http://xn--o80by81agsfmwa85o.vom77.com - 카지노주소

The flower language is being over the subject

The flower language is being over the subject <a href="http://vmm789.com" target="_blank">카지노사이트</a> <a href="http://cc.vmm789.com" target="_blank">바카라사이트</a> <a href="http://dd.vmm789.com" target="_blank">온라인카지노</a> <a href="http://et.vmm789.com" target="_blank">온라인바카라</a> <a href="http://tt.vmm789.com" target="_blank">룰렛사이트</a>

Add new comment

Target Image