Comments (4)
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.
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.
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.
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)
- pid weirdness with gproc_dist HOT 7
- Some gproc_dists_tests are very unstable (namely, t_sync_cand_dies, t_fail_node, t_master_dies) HOT 6
- Compiling with OTP 20 yields warnings about crypto:rand_uniform/2 HOT 4
- goodbye() doesn't work in global mode HOT 1
- Can't reset a shared counter
- Unable to start processes in global mode (Elixir)
- Generic server gproc terminating on reg HOT 2
- Warning On OTP 21.2 HOT 1
- aggregated counter can leak HOT 1
- Removing a worker from a pool does not make room for a new worker HOT 1
- gproc_pool round_robin is broken a bit HOT 2
- Monitor stops working if one of the processes monitoring the same name terminates
- Has gen_leader been deprecated ? HOT 1
- Replace key owner HOT 4
- local_only exception error when trying to register Pid golobally HOT 8
- OTP Release 23 depreciated functions HOT 1
- Use a stable app version number HOT 2
- The value of `auto_size` is not judged when the worker is removed HOT 1
- Relase for OTP 24 HOT 2
- If gproc:await finishes with timeout then generic leader gproc_dist terminating with error.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gproc.