tags:

views:

581

answers:

2

Hi,

I am using the following code fragment in a php script to safely update a shared resource.

$lock_id = sem_get( ftok( 'tmp/this.lock', 'r'));
sem_acquire($lock_id)
//do something
sem_release($lock_id)

When I stress test this code with large number of requests I get an error:

Warning: semop() failed acquiring SYSVSEM_SETVAL for key 0x1e: No space left on device in blahblah.php on line 1293

php sources show the following code for failed acquiring SYSVSEM_SETVAL

while (semop(semid, sop, 3) == -1) {
    if (errno != EINTR) {
     php3_error(E_WARNING, "semop() failed acquiring SYSVSEM_SETVAL for key 0x%x: %s", key, strerror(errno));
     break;
    }
}

which means semop fails with EINTR. man page reveals that the semop() system call was interrupted by a signal.

My question is can I safely ignore this error and retry sem_acquire?

Edit: I have misunderstood this problem, Pl see the clarification I have posted below.

raj

+1  A: 

I wouldn't ignore the ENOSPC (you're getting something other than EINTR, as the code shows). You may end up in a busy loop waiting for a resource that you have earlier exhausted. If you're out of some space somewhere, you want to make sure that you deal with that issue. ENOSPC generally means you are out of...something.

A couple of random ideas:

I am not an expert on the PHP implementation, but I'd try to avoid calling sem_get() each time you want the semaphore. Store the handle instead. It may be that some resource is associated with each call to sem_get, and that is where you're running out of space.

I'd make sure to check your error returns on sem_get(). It's a code snippet, but if you were to fail to get the sema4, you would get inconsistent results when trying to sem_op() it (perhaps EINTR makes sense)

bog
A: 

After posting this question I noticed that I misread the code as errno == EINTR and jumped into conclusion. So as bog has pointed out, the error is ENOSPC and not EINTR. After some digging I located the reason for ENOSPC. The number of undo buffers were getting exhausted. I have increased the number of semmnu and now the code is running with out issues. I have used semmni*semmsl as the value of semmnu

Rajkumar S