Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion moving process state - copy on write - heap memory increase

Received: by 10.205.139.2 with SMTP id iu2mr1726580bkc.7.1347399930604;
        Tue, 11 Sep 2012 14:45:30 -0700 (PDT)
X-BeenThere: erlang-programming@googlegroups.com
Received: by 10.204.148.136 with SMTP id p8ls1060657bkv.3.gmail; Tue, 11 Sep
 2012 14:45:30 -0700 (PDT)
Received: by 10.204.10.88 with SMTP id o24mr1722623bko.0.1347399930220;
        Tue, 11 Sep 2012 14:45:30 -0700 (PDT)
Received: by 10.204.10.88 with SMTP id o24mr1722622bko.0.1347399930201;
        Tue, 11 Sep 2012 14:45:30 -0700 (PDT)
Return-Path: <erlang-questions-boun...@erlang.org>
Received: from hades.cslab.ericsson.net (hades.cslab.ericsson.net. [192.121.151.104])
        by gmr-mx.google.com with ESMTP id j4si4003043bkj.3.2012.09.11.14.45.30;
        Tue, 11 Sep 2012 14:45:30 -0700 (PDT)
Received-SPF: pass (google.com: domain of erlang-questions-boun...@erlang.org designates 192.121.151.104 as permitted sender) client-ip=192.121.151.104;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of erlang-questions-boun...@erlang.org designates 192.121.151.104 as permitted sender) smtp.mail=erlang-questions-boun...@erlang.org
Received: from hades.cslab.ericsson.net (hades [192.121.151.104])
	by hades.cslab.ericsson.net (Postfix) with ESMTP id C90F45C11E;
	Tue, 11 Sep 2012 23:45:20 +0200 (CEST)
X-Original-To: erlang-questi...@erlang.org
Delivered-To: erlang-questi...@erlang.org
Received: from mail2.student.tuwien.ac.at (mail2.student.tuwien.ac.at
 [193.170.74.22])
 by hades.cslab.ericsson.net (Postfix) with ESMTP id F27735C006
 for <erlang-questi...@erlang.org>; Tue, 11 Sep 2012 23:45:18 +0200 (CEST)
Received: from [10.11.0.107] ([78.104.162.22]) (authenticated bits=0)
 by mail2.student.tuwien.ac.at (8.13.8/8.13.8) with ESMTP id q8BLjINb019189
 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO)
 for <erlang-questi...@erlang.org>; Tue, 11 Sep 2012 23:45:18 +0200
Message-ID: <504FB0EE.6010208@student.tuwien.ac.at>
Date: Tue, 11 Sep 2012 23:45:18 +0200
From: Roland <roland.koel...@student.tuwien.ac.at>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
 rv:15.0) Gecko/20120827 Thunderbird/15.0
MIME-Version: 1.0
To: erlang-questi...@erlang.org
Subject: [erlang-questions] moving process state - copy on write - heap
	memory increase
X-BeenThere: erlang-questi...@erlang.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: General Erlang/OTP discussions <erlang-questions.erlang.org>
List-Unsubscribe: <http://erlang.org/mailman/options/erlang-questions>,
 <mailto:erlang-questions-requ...@erlang.org?subject=unsubscribe>
List-Archive: <http://erlang.org/pipermail/erlang-questions>
List-Post: <mailto:erlang-questi...@erlang.org>
List-Help: <mailto:erlang-questions-requ...@erlang.org?subject=help>
List-Subscribe: <http://erlang.org/mailman/listinfo/erlang-questions>,
 <mailto:erlang-questions-requ...@erlang.org?subject=subscribe>
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset="us-ascii"; Format="flowed"
Errors-To: erlang-questions-boun...@erlang.org
Sender: erlang-questions-boun...@erlang.org

Hello!

I want to move the state of my process to another process. Unfortunately 
this is not possible without a huge increase in memory consumption as by 
copying the state the "copy on write semantics" are lost.

This behaviour is demonstrated in my attached simplified t_process module.

-> {ok, Pid} = t_process:start_link().
-> t_process:bloat(Pid). --> memory consumption of the process is at 
6657256 after "bloat" is finished
-> t_process:reload_bag(P1). --> memory consumption is at 26295176 (4 
times as much)

No data has not been modified in any way, the data stays the same.

My question is: Despite what i want to do with this state transfer, is 
there any way to copy the state of a process without losing the "copy on 
write semantics", so that the target process has the same memory 
footprint as the original one?

Can someone point me to any direction/documentation on how i can get 
arround this issue?

Thank you!

-module(t_process).

-behaviour(gen_server).

-export([start_link/0, init/1, handle_call/3, handle_cast/2, 
handle_info/2, terminate/2, code_change/3, bloat/1, reload_bag/1]).

-record(process, {bag = []}).

start_link() ->
	gen_server:start_link(?MODULE, [], []).

bloat(Pid) ->
     gen_server:cast(Pid, bloat).

reload_bag(Pid) ->
     gen_server:call(Pid, reload_bag).

init([]) ->
	{ok, #process{}}.

handle_call(reload_bag, _From, State) ->
     BinaryBag = erlang:term_to_binary(State#process.bag), % simulate 
state transfer / loss of semantics
     io:format("Bag size is ~w.", [erlang:size(BinaryBag)]),
     {reply, ok, State#process{bag = erlang:binary_to_term(BinaryBag)}};

handle_call(_Call, _From, State) ->
     {reply, ok, State}.

handle_cast(bloat, State) ->
     NewBag = lists:concat([State#process.bag, lists:foldl(fun(_C, List) 
-> List ++ [{"ABCDEFGHIJKLMNOPQRSTUVWXYZ"}] end, [], lists:seq(1, 50000))]),
     io:format("Bloating finished."),
     {noreply, State#process{bag = NewBag}};

handle_cast(_Cast, State) ->
     {noreply, State}.

handle_info(_Info, State) ->
     {noreply, State}.

terminate(_Reason, _State) ->
     ok.

code_change(_OldVsn, State, _Extra) ->
     {ok, State}.

_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions