I am going to design a website using ruby on rails. And one of the features i want to implement is the chat functionality. Where users can chat with the other users/members of the website. What i should be using or in other words start learning in order to design something like that ?
Is XMPP the answer. if so, i would be glad if someone could be a bit descriptive on where to go from there and/or suggest some books. thanks !
I said XMPP because i know Facebook uses that and i plan to create something similar
Protocols can become a pretty hairy topic, implementing a well-working protocol yourself can be pretty daunting without prior experience. Especially if it has to do with (near) real-time communication between several parties. If this is supposed to scale to any significant number of visitors, implementing this correctly can be pretty tough.
XMPP is a protocol that is already well established, is shaken down and already has many stable implementations. So when using it, you do not need to worry about designing or implementing the protocol anymore. For that reason, I'd really recommend it. It's also a rather easy to understand protocol, even if you will have to spend some time reading up on the basics in the beginning. Look neigh further than http://xmpp.org for documentation.
Setting up an XMPP server can be done in minutes, depending on your OS and the server you choose. The caveat is that if you want to customize the server at all, you will have to learn about the innards of it as well to some degree, which may or may not take some time.
The bottom line is: choosing XMPP and existing XMPP libraries and servers, you get 90% of the functionality for free and can concentrate on implementing your client. The question is, how much will you have to dig into the details of XMPP and the server, will this take longer than rolling your own protocol and will your own protocol suit your needs in the long term as well as XMPP would?
You always have to think about how much you want to spend on implementing this.
If you go with XMPP you will be able to run a XMPP standard chat server (outside of Rails) and should be able to use a JavaScript Client with a XMPP to HTTP Bridge.
A project a quick Google Search brought up doing this is Strophe.
But I'd argue that you should think long and hard about if XMPP really suits your needs and if you really want to go through all that trouble for a Chat.
Implementing your own is also not straightforward, especially when you are writing all the long-polling and signaling stuff yourself.
But it's not impossible and should give you a simple working solution in a couple of days.
Doing the chat yourself in Rails will require you however to use an alternative Database since Rails can't store data in-memory between requests and persisting chat data in ActiveRecord seems like not a very scalable and good idea.
Using XMPP obviously has the benefit of your users being able to connect to your Chat service using iChat, Jabber or any other XMPP Client..
Related
I am looking for advice to save me time. I am planning to create a Q&A web app for my university, a stackoverflow clone. I know Rails and I know Angular but I never used them together. One option for me is to use Firebase APIs because it's simple. My question is which is easier, making Angular consume Rails APIs, or firebase APIs? Or is it the same steps no matter what I use to create the APIs ?
This is not going to be the same process. It's also not a direct comparison.
Firebase is a hosted third party 'backend-as-a-service' and you use what they give you for API calls, but you can more or less rely on the API working as advertised (though the docs can be less than useful in places).
That is vs building your own RoR API, which means just that - you pick the groceries just as you want them, but you also get to fix all the bugs on both your API and and your client. You also still need a DB selected.
A more direct comparison would be 'should I pick Node or RoR.' Your question as it's posed is really a question of your own backend implementation or a hosted package.
Which is easier?
There is not a real, single answer.
If by easier you mean 'most direct', Firebase has an Angular library called AngularFire. It translates a lot of Firebase paradigms into a pretty familiar Angular pattern, with a couple of nice extras. You focus on your client code and DB design, it handles the server operations. That seems fairly direct to me.
If by easier you mean 'most flexibility', it's hard to see how building your own doesn't give you that.
If by easier you mean 'less work for me', then 'it depends'. If you are comfortable writing RoR backends and less familiar with NoSQL patterns, then you can probably put it together faster on your own setting your API methods and selecting a DB you are comfortable with. If you feel stronger with Angular than RoR, then learning Firebase paradigms might be a shorter climb.
For what it's worth, given its limited set of API calls, there is probably more focused support for specific questions about Firebase. But you do sacrifice the option of doing it 'your way,' and the RoR community is far larger than Firebase's so you can probably still get plenty of help. Like I said, it can really depend.
I need a way for my web application to send push-notifications to the client side. Realtime is not a strong requirement, near-realtime is okay. I don't need anything fancy, just sending a string to the client every now and then, nothing more. What's really important is that the solution must be very simple and low-profile (performance-wise mainly). Could you give me advice on which framework to use?
Many people would say SignalR hands down, but I'm not sure about the performance part. It is not disqualified, I'll tell about my doubts below, and I'm also interested about any insights you may have about this, but the main question stays what I wrote above.
I read this article recently. What it provides is a long-running request pattern with only a few classes, a little IIS & async magic and nothing more. Even if you have an IIS connection limit of 200, it will barely use up any of those connections. Compared to this, SignalR is as complex and heavy-weight as a nuclear power plant. It comes with half a dozen different DLL's (like OWIN, which I haven't heard about before, and even after a bit of Googling, I can't figure out what it is). The performance wiki page of SignalR starts by suggesting to increase your concurrent request limit to a ridiculous amount. So I'm guessing it's not using the aforementioned "trick". I'm not exactly sure how bad that is, but in the light of that article, it doesn't sound good.
If you really want to push messages to the client, SignalR approach is very good. As far as I know it works with web-sockets. Try to digg this way. Here is some article for the beginning:
http://blogs.msdn.com/b/youssefm/archive/2012/07/17/building-real-time-web-apps-with-asp-net-webapi-and-websockets.aspx.
For mobile apps I would use great library PushSharp. https://github.com/Redth/PushSharp
With help of PushSharp you can send notifications to any mobile app: WindowsPhone, IOS, Android, Blackberry etc.
Please note: sending push notification differs from platform to platform.
Keep in mind approach with pinging server all the time and checking for new messages. It is probably the easiest way.
I use SignalR and toastr.js. SignalR can scale to thousands of connections. There are also native SignalR clients for iOS and Android (check out Signalr-ObjC).
Since noone answered about the resource requirements and my doubts about SignalR, which was the key question here, I'm accepting this as an answer: http://www.codeproject.com/Articles/27107/Scalable-COMET-Combined-with-ASP-NET .
As it is evident that AJAX based chats do not scale, so what would you use for chats? Custom servers? Or any other methods?
Since with Rails each chat connection will take lots of memory, it won't be feasible to even have Rails run for each message. What do you recommend for use here?
I also tried to implement a sample chat app with AJAX (in built Ajax.updater) but it didn't workout. I'm sure there might be some good ajax solution.
But since this is based on server push technology, try Juggernaut (http://juggernaut.rubyforge.org/). I personally haven't tried, but it seems like it's good.
Or else consider web sockets (in HTML5) if possible.
People often use Evented Ruby for handling problems like this https://github.com/eventmachine/eventmachine one of the examples in a talk I went to at railsconf 2010.
For example http://playtype.net/past/2009/3/11/mini_an_eventmachine_clone_of/ is a evented ruby implementation of an irc bot
Unfortunately your post is based on a false premise. AJAX based chat certainly can scale, you just have to do it the right way. Juggernaut 2, for example, uses Node.js to handle many concurrent connections. You're right, you won't be able to handle 10,000 connections on a single server. That's what load balancing is for.
Do you have some data based on quantitative testing (aside from your own qualitative conclusions)?
Why create any kind of custom server for chat? IRC has been around for quite a while and is tried and tested.
The real question here should be about client-side implementations rather than trying to reinvent the wheel server side imo.
I'm trying to write a scalable interactive chat application for an existing high traffic website. It needs to be scalable on day 1, and chat's concurrency and multi-broadcast issues make it a tricky thing to scale.
My initial plan was to write the whole thing in rails and refactor the chat server into erlang later.
Although I am an experienced PHP dev and sysadmin, both node.js and RoR are new and extremely alien technologies to me, so I could use a little help understanding the core concepts and applications in this scenario. With so many new technologies, it is hard to understand them all.
Firstly, I recommend you review http://ajaxim.com/. The software is a pre-packaged version of what you want that relies on Node JS (far easier than rolling your own).
If you still want to write something yourself and have no experience with either technology, I recommend you review some introductory materials:
Node JS and Rails
The two sources are not free but will give you a quick one hour crash course on each technology.
You can also have a look at http://pusherapp.com ! This is if you want to implement a chat app right away.
If on the other hand, you want to implement one all by yourself, Node.js + Socket.io is your best bet. However, if you want chat rooms and stuff, have a look at this:
http://github.com/shripadk/express-juggernaut-demo
This demo app uses Express.JS framework and Juggernaut 2.
I would suggest going for only Node.js if you are building apps that require high concurrency. Its fairly easy to implement a chat room using Node.js compared to other server-side languages (mainly thanks to modules like socket.io). The event-driven architecture of Node.js makes it really easy to implement such stuff. The only catch with Node is that you have to think everything asynchronous! If you are good at Javascript then Node.js should be easy to learn.
I want to do a fairly simple implementation of a chat app using rails. from a theoretical standpoint I feel that ajax streaming pattern should be the way to go. However I am not sure, how it works and what are the potential disadvantages of this pattern?
Is there anything better that I can use. My requirement is to have four people on same web page and be able to see each others chat messages immediately in a group chat area. :)
It's a simple test app kind of thing. Any recommendations or pointers to implementations of streaming pattern would be helpful.
Cheers
Should keep you busy for a bit:
http://ajaxpatterns.org/HTTP_Streaming