[erlang-questions] Design question -- a valid or foolhardy approach to ets update?

Mihai Balea mihai@REDACTED
Tue Jul 14 13:41:31 CEST 2009


On Jul 14, 2009, at 6:02 AM, Steve Davis wrote:

> I am maintaining HTTP session data as records in an ETS table. This
> table is managed by a gen_server. However, each time the client makes
> a request the session expiry time needs to be updated, which means
> updating one field in the session record.
>
> In order not to bottleneck the gen_server process by having all
> clients contact the gen_server at every request, I'm considering a
> direct ETS update of the session record from the client process rather
> than doing a safe gen_server:call to update the record. i.e.:
>
> ...
> My reasoning is that since **only the client process** (meaning the
> spawned HTTP connection) will ever access its own record in the
> central ?ETS session table this approach should be safe to do... am I
> correct in my thinking or am I badly wrong somewhere? Is there some
> consideration I'm missing that could mean that this could result in
> lock contention or deadlock?

I don't know if what you're suggesting is feasible, but if it is not,  
have you considered using ets:update_counter/3?
It is probably faster than a gen_server process owning the table.

Mihai


More information about the erlang-questions mailing list