<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Well, I would expect copy_shallow (from ETS) to be less CPU
intensive<br>
than copy_struct (from process).<br>
<br>
However, as indicated by others, ets:lookup on such a big map will
probably<br>
trigger a garbage collection on the process, which will lead to<br>
yet another copy of the big map.<br>
<br>
The spawn(fun() -> do_something(BigMap) end) on the other hand
will<br>
allocate a big enough heap for the process form the start and only
do<br>
one copy of the big map.<br>
<br>
/Sverker, Erlang/OTP<br>
<br>
<br>
<div class="moz-cite-prefix">On 03/16/2016 10:43 AM, Alex Howle
wrote:<br>
</div>
<blockquote
cite="mid:CAC6pP+7mz_29NKjfOs26PE+GuYLTAZZyEBw2b=W9riZ1gDMP1w@mail.gmail.com"
type="cite">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<p dir="ltr">Assuming that when you say "win" you mean that
ets:lookup should be more efficient (and less CPU intensive)
then I'm seeing the opposite.</p>
<div class="gmail_quote">On 15 Mar 2016 11:32, "Sverker Eriksson"
<<a moz-do-not-send="true"
href="mailto:sverker.eriksson@ericsson.com">sverker.eriksson@ericsson.com</a>>
wrote:<br type="attribution">
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000"> Each successful
ets:lookup call is a copy operation of the entire term<br>
from ETS to the process heap.<br>
<br>
If you are comparing ets:lookup of big map<br>
to sending big map in message then I would expect<br>
ets:lookup to win, as copy_shallow (used by ets:lookup)<br>
is optimized to be faster than copy_struct (used by send).<br>
<br>
<br>
/Sverker, Erlang/OTP<br>
<br>
<br>
<div>On 03/15/2016 09:52 AM, Alex Howle wrote:<br>
</div>
<blockquote type="cite">
<p dir="ltr">I've been experiencing an issue and was
wondering if anyone else has any experience in this
area. I've stripped back the problem to its bare bones
for the purposes of this mail.</p>
<p dir="ltr"> </p>
<p dir="ltr">I have an Erlang 18.1 application that uses
ETS to store an Erlang map structure. Using
erts_debug:flat_size/1 I can approximate the map's size
to be 1MB. Upon the necessary activity trigger the
application spawns about 25 short-lived processes to
perform the main work of the application. This activity
trigger is fired roughly 9 times a second under normal
operating conditions. Each of these 25 processes
performs 1 x ets:lookup/2 calls to read from the map.</p>
<p dir="ltr"> </p>
<p dir="ltr">What I've found is that the above
implementation has a CPU profile that is quite
"expensive" - each of the CPU cores (40 total comprised
of 2 Processors with 10 hyperthreaded cores) frequently
runs at 100%. The machine in question also has 32GB RAM
of which about 9GB is used at peak. There is no swap
usage whatsoever. Examination shows that copy_shallow is
performing the most work.</p>
<p dir="ltr"> </p>
<p dir="ltr">After changing the implementation so that the
25 spawned processes no longer read from the ETS table
to retrieve the map structure and, instead the map is
passed to the processes on spawn, the CPU usage on the
server is considerably lower.<br>
</p>
<p dir="ltr"> </p>
<p dir="ltr">Can anyone offer advice as to why I'm seeing
the differing CPU profiles?<br>
</p>
<br>
<fieldset></fieldset>
<br>
<pre>_______________________________________________
erlang-questions mailing list
<a moz-do-not-send="true" href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a>
<a moz-do-not-send="true" href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a>
</pre>
</blockquote>
<br>
</div>
</blockquote>
</div>
</blockquote>
<br>
</body>
</html>