Skip to content

Implement Redis Pub/Sub #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Implement Redis Pub/Sub #1

wants to merge 6 commits into from

Conversation

ttanimichi
Copy link
Owner

@ttanimichi ttanimichi commented Jan 20, 2025

demo

rack hostname do
append preload "preload.rb"
endpoint Async::HTTP::Endpoint.parse("http://0.0.0.0:#{port}")
end
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it correct to place this file at the top level of the repo (not config/falcon.rb)?

Copy link

@ioquatix ioquatix Jan 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's correct. falcon host does not know about sub-directories like config.

end
end
end
end
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I specified --api when running rails new, but WebSocket should work fine too, right?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it should be fine.

end
end
end
end
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like domain logic, so I'm not sure if it's appropriate to write it in Controller. However, since it calls methods of connection instance, I still think Controller is the most suitable place for it, rather than Model or ServiceObject.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the design is okay, as the controller is focused on this particular use case. I think if you ended up with a more complex design, or wanted to isolate the logic for the sake of testing, you might prefer to use a service object.

@@ -0,0 +1,3 @@
server1: bin/rails s --port=3001 --pid=tmp/pids/server1.pid
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I use falcon serve instead of bin/rails s?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, bin/rails s uses Rackup which is very sub-optimal.

@@ -1,10 +1,7 @@
Rails.application.routes.draw do
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
root "home#index"
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm planning to use a reverse proxy like Nginx, which handles HTTPS termination, so I don't think there's a need to connect to the Rails app using HTTP/2.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HTTP/2 has a number of benefits, including the ability to handle far more WebSocket connections per HTTP network connection. HTTP/2 between the browser and the server must use TLS, but between servers it could be plain text HTTP/2. I'm not sure if nginx supports that.

Whether that is useful or not will depend on your scale requirements. Maybe you can comment on the number of active users you are hoping to support and the kind of deployment environment (number of servers, server hardware, etc) and I can give you more feedback.

* ...
```
$ bundle exec falcon host
```
Copy link
Owner Author

@ttanimichi ttanimichi Jan 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a production environment, is it sufficient to simply start with bundle exec falcon host regardless of the server's CPU core count? Even if a large number of Fibers are created, will there still only be a single Ruby process?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default bundle exec falcon host will start one server process per processor core, and one event loop per server process, which can handle multiple inbound requests.

If you only want a single process, you will need to configure count in your falcon.rb file https://socketry.github.io/falcon/source/Falcon/Environment/Server/index.html#Falcon::Environment::Server#count.

@ttanimichi ttanimichi marked this pull request as ready for review January 22, 2025 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants