I'm working on some code that will be run on Red Hat Enterprise Linux 3, which removed support for flock() over NFS. I've been asked to remove all the flock() calls in this script and replace them with calls to fcntl(). I've tested both, and whenever flock() is called, $! gets populated with something like "No locks available". fcntl() seems to do locking properly, but has some performance issues. For instance, if process A has a lock of some sort on a file and process B comes along and tries to get a F_WRLCK (exclusive write lock) lock using F_SETLCKW, B hangs appropriately until A releases it's lock. But after A releases it's lock, it seems to take about 18 seconds for B to wake back up again. Using flock() to do the same scenario on a RedHat 7.3 machine, B wakes up almost immediately. I'm thinking maybe part of the problem lies in the way I'm calling fcntl(). From "man fcntl" on a RHEL3 system, I see that the packed buffer should look like:
struct flock {
...
short l_type; /* Type of lock: F_RDLCK,
F_WRLCK, F_UNLCK */
short l_whence; /* How to interpret l_start:
SEEK_SET, SEEK_CUR, SEEK_END */
off_t l_start; /* Starting offset for lock */
off_t l_len; /* Number of bytes to lock */
pid_t l_pid; /* PID of process blocking our lock
(F_GETLK only) */
...
};
Not being a C hacker, I'm not sure what the template for pack() in my fcntl() call should look like, since I don't see anything in the pod about off_t or pid_t. I've just been assuming that that off_t could be a long and pid_t an int, like so:
fcntl(FILEHANDLE, F_SETLKW, pack("sslli", F_WRLCK, SEEK_SET, 0, 0, 0))
+;
A co-worker suggested I also try:
fcntl(FILEHANDLE, F_SETLKW, pack("s!s!l!l!i!", F_WRLCK, SEEK_SET, 0, 0
+, 0));
I'm not even sure what the bangs do exactly, but this didn't seem to help any. Am I creating the packed buffer correctly? If so, is there anything that can be done to help the performance? 18 seconds is way, way too slow.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.