Search code examples
erlangriakerlang-shellriak-search

How to continously load data in Riak with erlang file


I want to run a programme that loads a data into riak database, but the process is stopping suddenly when i gave range about 10. if i gave 5-8 it is taking and loading the data, when i give range more than 10 it was hanging up. what was happening.

test(X,Y) ->

if X < Y ->
    {ok,Pid} = riakc_pb_socket:start_link("127.0.0.1",10017),
    Val = X,
    io:format("~p",[Pid]),
    Object = riakc_obj:new(<<"test_age">>,undefined,Val),
    riakc_pb_socket:put(Pid,Object),
    test(X+1,Y);
true -> []
end.

The function will take a range of numbers and just insert into the riak database with adding the numbers to the old number.

when i run this programme from the erlang shell it is stopping after taking the range about 10:

erlriak:test(1,5)
<0.50.0><0.51.0><0.52.0><0.53.0><0.54.0>[]
erlriak:test(5,15)
<0.62.0><0.63.0><0.64.0><0.65.0><0.66.0><0.67.0><0.68.0><0.69.0><0.70.0>|

It was hanging after the <0.70.0> for minutes and nothing is returning.I am getting the following:

=ERROR REPORT==== 19-May-2014::17:29:54 ===
** Generic server <0.104.0> terminating 
** Last message in was {req_timeout,#Ref<0.0.0.423>}   
** When Server state == {state,"127.0.0.1",10017,false,false,undefined,false,
                           gen_tcp,undefined,
                           {[],[]},
                           1,[],infinity,undefined,undefined,undefined,
                           undefined,[],100}
** Reason for termination == 
** disconnected
** exception exit: disconnected

Solution

  • I suspect you are exceeding the limit for simultaneous connections to Riak's PB port. Possible solutions:

    • call riakc_pb_socket:stop(Pid) to close the connection before recursing
    • move the call to start_link outside the test function so all requests share the same socket
    • increase pb_backlog in your app.config so you can have more simultaneous connections