[erlang-questions] ETS delete_trap

James Aimonetti james@REDACTED
Tue Apr 26 16:39:44 CEST 2016

Hash: SHA256

On 04/26/2016 12:37 AM, Lukas Larsson wrote:
> On Tue, Apr 26, 2016 at 1:30 AM, James Aimonetti <james@REDACTED>
> wrote:
>> The curious bit that I can't really figure out is the 
>> {current_function, {ets,delete_trap,1}} bit from the
>> process_info/1 call (output below). As far as I can tell, that is
>> buried in the VM's C code.
> The delete_trap function is used when you are calling either 
> ets:select_delete/2 or ets:delete/1 on a table with many many
> elements.
> When working with ets tables that have many elements, erts takes
> smaller chunks of the table at a time and reschedules the process
> doing the processing.
> So for ets:delete it would first delete the first X elements
> (calling delete), then reschedule, then delete the next X (calling
> delete_trap), and so on deleting X records per iteration. Most ets
> functions work this way in order to not hog the schedulers for too
> a long time when working with large tables.
> Lukas

This makes sense to a degree. We read the ETS table (protected, set)
from the worker process to see if there are any entries that should be
erased and cast into the gen_listener process to erase the individual
entries by key. The table is large-ish, maybe 1.5GB, but we are using
ets:delete(Tab, Key) for each Key found in the worker process (there
are associated callbacks so client code can be notified if the cached
entry is flushed/erased) which I assume should be fast. The only other
delete operation is to flush the whole table with

We haven't tried enabling the read/write concurrency flags yet; would
write_concurrency make a difference when calling ets:delete/2? This is
18.2 too, by the way. Sorry for not mentioning that first.

Any tips on profiling ETS usage and finding efficiencies?

Thanks for the information so far.

- -- 
James Aimonetti
Lead Systems Architect / Impressionable Scallywag
"If Dialyzer doesn't care, I don't care"

2600HzPDX | http://2600hz.com
irc:mc_ @ freenode
Version: GnuPG v2
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/


More information about the erlang-questions mailing list