[erlang-questions] How to manage C ports that are suppose to handle a very high number of requests

Arshad Ansari arshadansari27@REDACTED
Thu Sep 1 08:27:08 CEST 2016


Hello Daniel,

> 1. You are initializing and destroying Lua context for every call.  Can
this be done just once for the whole program?
I intend to keep lua context between calls but then I'm not sure how it
will affect the subsequent calls. If the lua_State* is same for multiple
calls then that state would have the file loaded once and I'm not sure if
pushing and poping the arguments and return values from lua context would
create problems or not.
> 2. I count at least 5 read()/write() calls for each command which are
somewhat expensive.  Can that be reduced?  Also consider batching a whole
bunch of commands with a single read()/write().
read()/write() calls erlang to c-port? I simply followed a blog example do
this, since I'm very new to both C as well as erlang. I'm not getting the
link right now, I'll post it in this thread as soon as I find it. I will
look into reducing those calls.

Thanks for the reply and for pointing out areas of improvements.

Regards,
Arshad

On Thu, Sep 1, 2016 at 12:58 AM Daniel Goertzen <daniel.goertzen@REDACTED>
wrote:

> I don't know much about Lua or why you had a stack overflow, but I have
> some performance concerns about that C code:
>
> 1. You are initializing and destroying Lua context for every call.  Can
> this be done just once for the whole program?
>
> 2. I count at least 5 read()/write() calls for each command which are
> somewhat expensive.  Can that be reduced?  Also consider batching a whole
> bunch of commands with a single read()/write().
>
> Regards,
> Dan.
>
> On Thu, Aug 25, 2016 at 8:01 AM Arshad Ansari <arshadansari27@REDACTED>
> wrote:
>
>> Hello there,
>>
>> I had earlier asked about how to access LuaJIT from erlang [
>> http://erlang.org/pipermail/erlang-questions/2016-August/089939.html
>> <http://erlang.org/pipermail/erlang-questions/2016-August/089939.html%5C>]
>> and based on the responses, I decided to go with C port. It was working all
>> great. Except, when I tried to call the same C-Port [luajit] code from
>> erlang-diameter server. Since the requests were high, but not very high
>> (approx 10K per second), the code fails with stack overflow on c side.
>>
>> Now I thought, I would create a seperate C port for each requests but
>> that would mean there will be around 10K c-port processes. I'm now
>> wondering how to handle this size of requests from the c port. Any help or
>> direction is appreciated. Please let me know if my question is not clear.
>> I'm attaching the code to access lua that works with single instance of
>> c-port process.
>>
>> Regards
>> Arshad
>>
>> /************ CODE Details *********************/
>>
>> erl_com.c contains code to send/receive data from c side
>> port.c runs the lua code and has main
>> script.lua
>> relay.erl starts the relay server and c port to talk to lua
>> relay_cb.erl handles requests and communicates with lua
>>
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20160901/158cbfb9/attachment.htm>


More information about the erlang-questions mailing list