[erlang-questions] HTTP client with sessions support
Ulf Wiger
ulf@REDACTED
Sat Jun 13 23:12:59 CEST 2015
> On 13 Jun 2015, at 21:35, Ingela Andin <ingela.andin@REDACTED> wrote:
>
> Creating a name for the profile is not that heavy?! The ets-table is an implementation detail not written in stone, it could use some other data structure like a dict or something. Feel free make a PR, if you make a good case it can be changed.
Creating an ets table really isn’t a heavy operation.
Consider the following program:
-module(etsc).
-compile(export_all).
t(N) when N > 0 ->
T = ets:new(t, []),
ets:delete(T),
t(N-1);
t(_) ->
ok.
Eshell V5.10.4 (abort with ^G)
1> c(etsc).
{ok,etsc}
2> timer:tc(etsc,t,[1000]).
{2775,ok}
3> timer:tc(etsc,t,[1000]).
{2612,ok}
4> timer:tc(etsc,t,[1000]).
{2055,ok}
5> timer:tc(etsc,t,[1000]).
{1881,ok}
That is, on my old Macbook Air, it takes about a microsecond to create an ets table*.
Creating an atom is also obviously cheap, but I cringe a bit when list_to_atom/1 is used in generic code - although in this particular case, I guess creating memory leaks because of it is not very likely.
BR,
Ulf W
* Obviously, this test doesn’t accumulate ets tables. I removed the ets:delete/1 call, and things looked much worse:
- Creating the first 1000 tables took ca 13 ms.
- Creating 1000 tables when there were already 67K tables, took 6.2 seconds.
- However, creating an ets table from another process was still pretty fast - ca 10 usec
I conclude that having thousands of ets tables owned by a single process is a *bad* idea (probably not for this reason alone).
Ulf Wiger, Co-founder & Developer Advocate, Feuerlabs Inc.
http://feuerlabs.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150613/f902e898/attachment.htm>
More information about the erlang-questions
mailing list