Git Product home page Git Product logo

Comments (4)

uwiger avatar uwiger commented on July 22, 2024

Hi Adam,

You need to create shared counters using gproc:reg_shared().

The counter you created with gproc:reg/1 is not a shared counter, but a
'normal' one (registered to the current process). Thus,
update_shared_counter/2 can't find it.

BR,
Ulf W

Den 27 mars 2012 15:21 skrev Adam Denenberg <
[email protected]

:

hello,

I am trying to keep track of the number of connected users to a process
inside of cowboy (for a websocket connection).

My code is as follows:

Inside of cowboy websocket_init:

gproc:reg({c,l,wsCounter}),
gproc:update_shared_counter({c,l,wsCounter},1)

Error Stacktrace:

** Stacktrace:
[{ets,update_counter,[gproc,{{c,l,wsCounter},shared},{3,1}],[]},
{gproc_lib,update_counter,3,
[{file,"src/gproc_lib.erl"},{line,370}]},
{gproc,update_shared_counter,2,
[{file,"src/gproc.erl"},{line,1299}]},
{erltest1_http_handler,websocket_init,3,
[{file,"src/erltest1_http_handler.erl"},{line,46}]},

Any thoughts?

Thanks
-A


Reply to this email directly or view it on GitHub:
#17

from gproc.

denen99 avatar denen99 commented on July 22, 2024

thanks, getting closer.. i did

gproc:reg_shared({c,l,wsCounter}),
gproc:update_shared_counter({c,l,wsCounter},1),
io:format("cowboy: Current count is pn,",[gproc:get_value({c,l,wsCounter})]),

but its throwing:

** Stacktrace: [{ets,lookup_element,[gproc,{{c,l,wsCounter},<0.164.0>},3],[]},
{gproc,get_value1,2,[{file,"src/gproc.erl"},{line,1087}]},
{gproc,get_value,1,[{file,"src/gproc.erl"},{line,1068}]},
{erltest1_http_handler,websocket_init,3,
[{file,"src/erltest1_http_handler.erl"},{line,47}]},

Thanks
-A

from gproc.

denen99 avatar denen99 commented on July 22, 2024

nevermind i got it. I had to move reg_shared into my startup function not the websocket init handler.

so i ended up with just

gproc:update_shared_counter({c,l,wsCounter},1), in websocket_init

and

gproc:update_shared_counter({c,l,wsCounter},-1) in websocket_terminate

from gproc.

uwiger avatar uwiger commented on July 22, 2024

If you want to call get_value() on a shared counter, you must use
gproc:get_value/2,
e.g.

gproc:get_value({c,l,wsCounter}, shared).

BR,
Ulf W

Den 27 mars 2012 16:04 skrev Adam Denenberg <
[email protected]

:

thanks, getting closer.. i did

gproc:reg_shared({c,l,wsCounter}),
gproc:update_shared_counter({c,l,wsCounter},1),
io:format("cowboy: Current count is
pn,",[gproc:get_value({c,l,wsCounter})]),

but its throwing:

** Stacktrace:
[{ets,lookup_element,[gproc,{{c,l,wsCounter},<0.164.0>},3],[]},
{gproc,get_value1,2,[{file,"src/gproc.erl"},{line,1087}]},
{gproc,get_value,1,[{file,"src/gproc.erl"},{line,1068}]},
{erltest1_http_handler,websocket_init,3,
[{file,"src/erltest1_http_handler.erl"},{line,47}]},

Thanks
-A


Reply to this email directly or view it on GitHub:
#17 (comment)

from gproc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.