Comments (8)
There are two places where I think the change could be made:
Phoenix.PubSub.Local
def subscribers_with_fastlanes(pubsub_server, topic, shard) when is_atom(pubsub_server) do
try do
topics = List.wrap(topic)
local = local_for_shard(shard, pubsub_server)
# there may be a more efficient way to do this with :ets.select/2 and a match spec
Enum.reduce(topics, [], fn(topic, subscribers) ->
fast_concat(:ets.lookup_element(local, topic, 2), subscribers) end)
catch
:error, :badarg -> []
end
end
defp fast_concat([], list),
do: list
defp fast_concat([h|t], list),
do: fast_concat(t, [h|list])
Phoenix.PubSub.PG2Server
def handle_info({:forward_to_local, fastlane, from_pid, pool_size, topics, msg}, name) do
# The whole broadcast will happen inside the current process
# but only for messages coming from the distributed system.
for topic <- topics, do:
Local.broadcast(fastlane, name, pool_size, from_pid, topic, msg)
{:noreply, name}
end
Putting the logic in Local is probably more maintainable. PG2Server is an adapter, so every new adapter will have to duplicate the code for handling lists.
from phoenix_pubsub.
This would be great to have! Found this via a related google groups discussion: https://groups.google.com/forum/#!msg/phoenix-core/0o-vNYj2Lok/gyXFHZ9iAAAJ
Since we have similar performance characteristics (although we may have many more people in a single room) I believe that this feature would help our performance.
from phoenix_pubsub.
@chrismccord @alex-shapiro I know it's been awhile since this was discussed. Anything we can do to help?
from phoenix_pubsub.
Also has anyone measured and found out this to be a performance bottleneck? From my understanding of the code, being able to batch broadcasts for multiple topics won't make a difference for local broadcasts (because we need to do a new lookup on the table for every topic) and for cases of distributed broadcasts we are only saving a single GenServer message.
So my understanding is that this change would save a couple function calls and one message, which certainly won't be the bottleneck if you are running at scale.
from phoenix_pubsub.
@josevalim I'm a little confused, in the above thread (the genesis for this ticket), you said:
Yup, just want to chime in and say it is definitely worth it perf wise.
Is that not the case then? Just curious if I'm missing something obvious 😄
from phoenix_pubsub.
I did not consider the cost of multinode communication. Thank you. :) So yes, this is worth doing but we only need to worry about it on the multinode aspect. I am assigning this to me.
from phoenix_pubsub.
Great, thank you!
from phoenix_pubsub.
This is going to be allowed in future incarnations of Phoenix.PubSub (more details about it later).
from phoenix_pubsub.
Related Issues (20)
- Latest Version of Phoenix.PubSub in Hex HOT 1
- broadcast_from!/4 is undefined or private HOT 1
- Network traffic up for 20 minutes after a server restart
- Release v1.1.3 suppressing warnings HOT 1
- Where is version 2.0? HOT 1
- It may be helpful for users, if parallel option can be provided when starting Registry. Without it partitions in registry executes sequentially. HOT 1
- unknown registry: XXX.PubSub HOT 4
- RFC: Provide a way to mass update presences HOT 1
- topic forced to be string HOT 1
- Race condition causing data inconsistency when nodes are coming up
- Does Phoenix.PubSub itself support subscribing to wildcard topics? HOT 1
- PubSub registry fails to start or race condition when testing? HOT 3
- [Feature Request] Be able to transform a module into a Pub.Sub HOT 6
- Unsubscribe all HOT 2
- v2.1 and v2.0 are incompatible
- Odd Jason Encoding error after new release HOT 2
- Broken Build Status link
- Presence list keep growing when using Presence.update HOT 3
- Presence stops working after ~1 week HOT 5
- Politely request release of 2.1.4
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 phoenix_pubsub.