Using Twitteroauth causes error(12) fork: Cannot allocate memory

Installing, Configuring, Troubleshooting server daemons such as Web and Mail
rwap
Posts: 20
Joined: 2010/10/28 16:49:33
Location: Stone, UK
Contact:

Using Twitteroauth causes error(12) fork: Cannot allocate memory

Post by rwap » 2010/11/28 17:43:08

I have Centos 5.5 running on a VPS - I have upgraded to PHP v5.2.14 with Zend Engine v2.2.0 and eAccelerator v0.9.6.1 installed.

My website runs fine, except when I attempt to use some code I have written to update twitter statuses through twitteroauth (their latest API for communicating with twitter).

The code works and is proven to update the status (it sends a maximum of 3 status messages), using CURL to communicate with the twitter engine

However, whenever I run this particular code, I get a mass of error messages in my error_log for example:
[Sun Nov 28 20:35:04 2010] [error] (12)Cannot allocate memory: fork: Unable to fork new process
[Sun Nov 28 20:35:14 2010] [error] (12)Cannot allocate memory: fork: Unable to fork new process
[Sun Nov 28 20:35:24 2010] [error] (12)Cannot allocate memory: fork: Unable to fork new process
[Sun Nov 28 20:35:34 2010] [error] (12)Cannot allocate memory: fork: Unable to fork new process
[Sun Nov 28 20:35:44 2010] [error] (12)Cannot allocate memory: fork: Unable to fork new process
[Sun Nov 28 20:35:54 2010] [error] (12)Cannot allocate memory: fork: Unable to fork new process
[Sun Nov 28 20:36:04 2010] [error] (12)Cannot allocate memory: fork: Unable to fork new process
[Sun Nov 28 20:36:14 2010] [error] (12)Cannot allocate memory: fork: Unable to fork new process
[Sun Nov 28 20:36:24 2010] [error] (12)Cannot allocate memory: fork: Unable to fork new process
[Sun Nov 28 20:36:34 2010] [error] (12)Cannot allocate memory: fork: Unable to fork new process
[Sun Nov 28 20:36:44 2010] [error] (12)Cannot allocate memory: fork: Unable to fork new process
[Sun Nov 28 20:36:55 2010] [error] (12)Cannot allocate memory: fork: Unable to fork new process
[Sun Nov 28 20:37:05 2010] [error] (12)Cannot allocate memory: fork: Unable to fork new process
[Sun Nov 28 20:37:15 2010] [error] (12)Cannot allocate memory: fork: Unable to fork new process
[Sun Nov 28 20:37:25 2010] [error] (12)Cannot allocate memory: fork: Unable to fork new process
[Sun Nov 28 20:37:35 2010] [error] (12)Cannot allocate memory: fork: Unable to fork new process
[Sun Nov 28 20:37:45 2010] [error] (12)Cannot allocate memory: fork: Unable to fork new process
[Sun Nov 28 20:37:55 2010] [error] (12)Cannot allocate memory: fork: Unable to fork new process


It is odd that this is once every 10 seconds.

On some occasions, the website still works after this, but on many ocassions, I have no option but to reboot the VPS.

Any suggestions as to what may be causing this issue?

Rich

gerald_clark
Posts: 10642
Joined: 2005/08/05 15:19:54
Location: Northern Illinois, USA

Using Twitteroauth causes error(12) fork: Cannot allocate me

Post by gerald_clark » 2010/11/29 14:34:19

Have your VPS supplier give you more memory.

rwap
Posts: 20
Joined: 2010/10/28 16:49:33
Location: Stone, UK
Contact:

Re: Using Twitteroauth causes error(12) fork: Cannot allocate memory

Post by rwap » 2010/12/01 23:00:06

I am not sure that is the issue - surely if a PHP process cannot fork due to lack of memory, the server should not need to be rebooted in any case?

Besides the available memory is 8GB and under normal processes my website uses only around 700MB - I can't believe that oaauth to twitter to update a status would use another 7GB !!

What I have noticed is that the CPU usage is normally around 39% user, 14% kernel, 0% IO, 46% idle, but when I call the code to update the twitter feed, this can increase to around 73% user, 21% kernel, 0% IO, 6% idle

Open to more ideas - maybe something in the settings as to how much memory can be used by a process (no idea where to find that)

User avatar
TrevorH
Site Admin
Posts: 33219
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Using Twitteroauth causes error(12) fork: Cannot allocate memory

Post by TrevorH » 2010/12/01 23:55:49

Please post the output from

[code]
grep memory_limit /etc/php.ini
[/code]

rwap
Posts: 20
Joined: 2010/10/28 16:49:33
Location: Stone, UK
Contact:

Re: Using Twitteroauth causes error(12) fork: Cannot allocate memory

Post by rwap » 2010/12/02 18:34:38

grep memory_limit /etc/php.ini returns the following:

memory_limit = 128M

User avatar
TrevorH
Site Admin
Posts: 33219
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Using Twitteroauth causes error(12) fork: Cannot allocate memory

Post by TrevorH » 2010/12/03 10:31:22

And how many apache processes are running when you get this error?

rwap
Posts: 20
Joined: 2010/10/28 16:49:33
Location: Stone, UK
Contact:

Re: Using Twitteroauth causes error(12) fork: Cannot allocate memory

Post by rwap » 2010/12/03 11:08:34

It jumps from 37 to 67 when I launch the call to twitteroauth. However, memory usage never seems to creep above 1GB.

Oddly the running processes take a while to close back down to the 37 level.

It is hard to tell how many processes are running when I get the error per se, as at that stage, the server is totally unresponsive and has to be rebooted!

More useful may be the CPU load at around the time:

CPU load averages 4.66 (1 min) 5.18 (5 mins) 2.32 (15 mins)
CPU usage 77% user, 22% kernel, 0% IO, 1% idle

User avatar
TrevorH
Site Admin
Posts: 33219
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Using Twitteroauth causes error(12) fork: Cannot allocate memory

Post by TrevorH » 2010/12/03 12:02:57

67 * 128MB = 8576MB

It's right.

How much swap space do you have defined? I'd look at trying to reduce that php.ini setting to see if you can fit into 8GB. Also what do you have for these settings:

[code]
# find /proc -name "*commit*"
/proc/sys/vm/overcommit_ratio
/proc/sys/vm/overcommit_memory
# cat /proc/sys/vm/overcommit_memory /proc/sys/vm/overcommit_ratio
0
50
[/code]

rwap
Posts: 20
Joined: 2010/10/28 16:49:33
Location: Stone, UK
Contact:

Re: Using Twitteroauth causes error(12) fork: Cannot allocate memory

Post by rwap » 2010/12/03 12:14:58

I get the same output:

# find /proc -name "*commit*"
/proc/sys/vm/overcommit_ratio
/proc/sys/vm/overcommit_memory
# cat /proc/sys/vm/overcommit_memory /proc/sys/vm/overcommit_ratio
0
50

I have reduced the php.ini setting to 96MB and 64MB, but still get the same problem - what I don't quite understand is that memory usage stays below 1GB which suggests that the PHP code is not using all of the memory available.

User avatar
TrevorH
Site Admin
Posts: 33219
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Using Twitteroauth causes error(12) fork: Cannot allocate memory

Post by TrevorH » 2010/12/03 13:48:53

I just had a quick google and found this illuminating thread [url=http://www.webhostingtalk.com/showthread.php?t=682317]here[/url] which talks about how the output from free does not reflect what is available to your VPS and gives some other things to check to see how much resource you actually have available.

Post Reply