kostonstyle

kostonstyle

Hi all
When I create a channel like:

channel "videos:*", Rumbl.VideoChannel

It will start a process for this channel? If yes, then only one process will handle all incoming events?
Thanks

Showing Posts 1 to 10

bratsche

bratsche

I think there’s a minimum of 2 processes for any given channel. There will be one PubSub process, and one process for each client/user.

OvermindDL1

OvermindDL1

When you create a channel like that it creates no processes.

However let me go through the whole process as I understand it (from debugging and reading a good bit of the code).

The client websocket/longpolling connects to the ‘Socket’ that you made, that spawns off a new process, thus (1) process so far, for the open socket. That socket process then checks if it is allowed via your own code and such, do whatever you want, set assigns that will be given to all other topic processes too. That socket then checks the topic being connected to and spawns another new process for just that topic (and each new topic connected comes in the same socket process but then makes a new topic etc…). That topic process gets a copy of the socket assigns (this way you can do something like get the user from the database and store in an assigns for all topics to see). So at this point you have two processes, and one additional process for each extra topic.

kostonstyle

kostonstyle OP

Thanks

webdeb

webdeb

If I understood it correctly, then a topic like “user:*” will be spawned once for all users, each user/client has be connected over a persistent socket (which itself is a process, sure), but there will be no additional processes for each user:#{id} topic, right?

OvermindDL1

OvermindDL1

Nope, a process is spawned for each topic for each user. You can join more topics from inside a topic though, and ‘those’ will not create more processes, but anytime the javascript sides connects to a topic for every single user then a new process is created for that specific topic/connection by default. :slight_smile:

webdeb

webdeb

Hmm, thank you, so., this can potentially become expensive.. I am wondering, how we could send a single message to an opened socket connection, on a single users topic but to an explicit single user. I mean simply like responding is happening..

I mean, you mentioned, that its possible to join an user to a topic without creating those processes.

So basically from JS channel = s.join('users') Inside users one would join to user:id but broadcasting messages wouldn’t reach the client side.. because there is no channel with the topic user:id defined.. :confused:

chrismccord

chrismccord

Creator of Phoenix

If you broadcast to a topic unique to a given user, say "user:123", only that user will receive the message. If you’re asking how to message to a single user 123’s devices, then you can use Phoenix Presence, but we need to know more info to know what your exact usecase is. Generally it’s just fine to broadcast to a private user topic since you usually want all tabs/devices the user has joined to receive the message.

OvermindDL1

OvermindDL1

Not too bad at all. Process’s are overall cheap.

You need to make at least one topic, as it is ‘that’ that can then join others without extra processes. You can broadcast just fine once the topic you made registers to them, like a socket joins "users" but that topic also internally joins "user:#{id}", then you could broadcast to "user:#{id}" and that "users" topic would get it just fine. :slight_smile:

webdeb

webdeb

Hi @chrismccord thank you for your attention. I’ll try to explain the use case:

10 users, each on a single device. All of them connect are connecting to the backend via WebSockets.
(For each of those is a socket process created, so far so good)

Now all of them join the room:lobby Another process is created, which holds the state of the channel and all its meta data.

Now each of them joins to the user:uuid channel.. As I understood, this will spawn another 10 processes (one for each wildcard uuid)

So, basically, the main question is, how send a single message to a particular user, (I could store a map like uuid -> socket on some generic topic like users ?

OvermindDL1

OvermindDL1

To a particular user? Just MyEndpoint.broadcast("user:uuid", ...) as normal. :slight_smile:
What about that does not work for you?

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 94592 917
New
cblavier
Hey there, It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
heathen
Quite interesting article Google brought me. Didn’t find any mentions about it here. What do you think in general? Would you use togethe...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
axelson
Hi there! :wave: @frigidcode and I (but mostly him) have been running an Elixir Book club, we’re almost done with Designing Elixir Syste...
New
AstonJ
Since we have deprecated our Erlang sections (as we have dedicated Erlang Forums now) let’s add this thread for those who’d like to post ...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews