[erlang-questions] Use several file server processes

Fisher, Paul pfisher@REDACTED
Tue May 30 21:03:17 CEST 2017


Use prim_file and create separate ports for each process you want to run fileops in parallel.  We have a fileops module that just creates ports and stuff it into the process dictionary to reused, which works out well, since lifecycle of the ports works with the lifetime of the process.  This works around the file_server_2 bottleneck.


These two functions should give you the idea:


read_file(Name) ->
        Port = get_port(),
        prim_file:read_file( Port, Name ).



get_port() ->
        case get( ?MODULE ) of
        undefined ->
        Port = case prim_file:start() of
        {ok, Port0} -> Port0;
        {error, Reason} ->
        exit( {?MODULE, failed_to_create_prim_file, Reason} )
        end,
        put( ?MODULE, Port ),
        Port;
        Port -> Port
        end.



--

paul

Fellow, Engineering

________________________________
From: erlang-questions-bounces@REDACTED <erlang-questions-bounces@REDACTED> on behalf of Vladimir Gordeev <gordeev.vladimir.v@REDACTED>
Sent: Tuesday, May 30, 2017 1:25:02 PM
To: erlang-questions@REDACTED
Subject: Re: [erlang-questions] Use several file server processes

I had an idea to use slave nodes expecting them so start their own independent file server,
but turns out it relays to master-node file server: http://erlang.org/doc/man/slave.html#start-1<https://urldefense.proofpoint.com/v2/url?u=http-3A__erlang.org_doc_man_slave.html-23start-2D1&d=DwMFaQ&c=L_h2OePR2UWWefmqrezxOsP9Uqw55rRfX5bRtw9S4KY&r=PevFox_7LK44ZV_jlS5jRM2WItKtsHV4zN_CrbdT2aM&m=KJpSrJr6iRBvp1ZKo2EdQdyYlmOCx67zfD_jtt_gnfk&s=3QVBGCL4ECFXCn4ED-W8ccFXRy-W_vEGgAjL5jToVbo&e=>

On Tue, May 30, 2017 at 7:57 PM, Vladimir Gordeev <gordeev.vladimir.v@REDACTED<mailto:gordeev.vladimir.v@REDACTED>> wrote:
Greetings,

I want to start separate erlang shell processes (via shell:start/2) on my erlang node. I want each of these shells to have their own CWD, that could be read/written by file:get_cwd/0, file:set_cwd/1.

I hoped to find something like that: http://erlang.org/doc/apps/stdlib/io_protocol.html<https://urldefense.proofpoint.com/v2/url?u=http-3A__erlang.org_doc_apps_stdlib_io-5Fprotocol.html&d=DwMFaQ&c=L_h2OePR2UWWefmqrezxOsP9Uqw55rRfX5bRtw9S4KY&r=PevFox_7LK44ZV_jlS5jRM2WItKtsHV4zN_CrbdT2aM&m=KJpSrJr6iRBvp1ZKo2EdQdyYlmOCx67zfD_jtt_gnfk&s=AP8cP2E7w6qDIUOUEKFcybBC9s9BXC_bOqm7X5hXSKA&e=> but for file operations.

I looked up in stdlib file.erl and discovered that it makes gen_server:call to process registered under file_server_2, which is hardcoded in source.

There is not way to achieve what I want?

Confidentiality Notice | This email and any included attachments may be privileged, confidential and/or otherwise protected from disclosure. Access to this email by anyone other than the intended recipient is unauthorized. If you believe you have received this email in error, please contact the sender immediately and delete all copies. If you are not the intended recipient, you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20170530/2dd07236/attachment.htm>


More information about the erlang-questions mailing list