mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-22 06:11:32 +02:00
MEDIUM: stick-table: switch to rdlock in stktable_lookup() and lookup_key()
These functions do not modify anything in the the table except the refcount on success. Let's just lock the table for shared accesses and make use of atomic ops to update the refcount. This brings a nice gain from 425k to 455k under 48 threads (7%), but some contention remains on the exclusive locks in other parts. Note that the refcount continues to be updated under the lock because it's not yet certain whether there are races between it and some of the exclusive lock on the table. The difference is marginal and we prefer to stay on the safe side for now.
This commit is contained in:
parent
175aa06232
commit
a7d6a1396e
@ -335,11 +335,11 @@ struct stksess *stktable_lookup_key(struct stktable *t, struct stktable_key *key
|
|||||||
{
|
{
|
||||||
struct stksess *ts;
|
struct stksess *ts;
|
||||||
|
|
||||||
HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &t->lock);
|
HA_RWLOCK_RDLOCK(STK_TABLE_LOCK, &t->lock);
|
||||||
ts = __stktable_lookup_key(t, key);
|
ts = __stktable_lookup_key(t, key);
|
||||||
if (ts)
|
if (ts)
|
||||||
ts->ref_cnt++;
|
HA_ATOMIC_INC(&ts->ref_cnt);
|
||||||
HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &t->lock);
|
HA_RWLOCK_RDUNLOCK(STK_TABLE_LOCK, &t->lock);
|
||||||
|
|
||||||
return ts;
|
return ts;
|
||||||
}
|
}
|
||||||
@ -373,11 +373,11 @@ struct stksess *stktable_lookup(struct stktable *t, struct stksess *ts)
|
|||||||
{
|
{
|
||||||
struct stksess *lts;
|
struct stksess *lts;
|
||||||
|
|
||||||
HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &t->lock);
|
HA_RWLOCK_RDLOCK(STK_TABLE_LOCK, &t->lock);
|
||||||
lts = __stktable_lookup(t, ts);
|
lts = __stktable_lookup(t, ts);
|
||||||
if (lts)
|
if (lts)
|
||||||
lts->ref_cnt++;
|
HA_ATOMIC_INC(<s->ref_cnt);
|
||||||
HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &t->lock);
|
HA_RWLOCK_RDUNLOCK(STK_TABLE_LOCK, &t->lock);
|
||||||
|
|
||||||
return lts;
|
return lts;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user