Opened 8 weeks ago

Last modified 7 weeks ago

#346 accepted enhancement

Patch to enable spinlocks (option)

Reported by: arnecls Owned by: moo
Priority: major Milestone: 3.3.0
Component: cacher Version: 3.1.0
Keywords: spinlock Cc:
Application: PHP Version:
Other Exts: SAPI: Irrelevant
Probability: Blocked By:
Blocking:

Description

This patch opens up the possibility to compile xcache so that a spinlock is used instead of a pthread / fcntl mutex. This does bring a performance benefit in heavy load scenarios and showed to be as stable as the "heavy weight" locks in production.

The spinlock has been compiled/tested on Intel CPUs with MacOSX (dev) and FreeBSD 9 (production).
Windows support has been added, too but has not been tested, yet (it compiles).

We would like to see this integrated into xcache, but it would also be nice to have another opinion on the code (maybe there are pitfalls which we didn't see or didn't encounter, yet).

Attachments (2)

spinlocks.diff (13.9 KB) - added by arnecls 8 weeks ago.
GIT diff file for xcache 3.1.0
signal.diff (8.3 KB) - added by arnecls 7 weeks ago.
PID based unlocking on signal

Download all attachments as: .zip

Change History (6)

Changed 8 weeks ago by arnecls

GIT diff file for xcache 3.1.0

comment:1 Changed 8 weeks ago by moo

  • Status changed from new to accepted

Will it be running well under multi-process-thread hybrid env? stable and fast. It seems the spinlock won't release itself if it is locked and the process die

comment:2 Changed 7 weeks ago by arnecls

It showed to be stable on our systems, but we did not have a process crashing there.
A process dying while holding a lock will cause a inter-process deadlock Situation, yes, but so does a pthread based solution, doesn't it?
Maybe this can be solved - at least for some cases - by using a signal handler (and lock with a pid instead of 1) but I don't know if this covers all scenarios.

comment:3 Changed 7 weeks ago by arnecls

The attached file contains a possible solution to a process crashing while holding a lock.
It also fixes a locking issue that sneaked in after the windows port.

Last edited 7 weeks ago by arnecls (previous) (diff)

Changed 7 weeks ago by arnecls

PID based unlocking on signal

comment:4 Changed 7 weeks ago by moo

  • Milestone changed from undecided to 3.2.1
Note: See TracTickets for help on using tickets.