Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Streaming with Node.js, or any other Comet solution

I'm trying to build a streaming solution for an internal app, but am drawing blanks for a solution to get past a roadblock. Currently, in my working example, I'm using APE, but due to restrictions I can't have any foreign running processes on the host machine, so I can't run the APE server.

I'm looking for alternatives, but everything I've found so far has required running processes on the server.

Some details about the project.

  • There will be approximately 25 people connected at one time
  • Ideally everyone should see the updates at the same time, as soon as they're available.
  • It will be running in a Windows environment, so C#/.NET solutions would be preferable over things like PHP.

Anyone have any ideas, if node.js is capable of handling this, or of any other solutions?

like image 623
A Wizard Did It Avatar asked Oct 17 '10 23:10

A Wizard Did It


People also ask

Is Nodejs good for streaming?

In Node. js, HTTP was developed with streaming and low latency in mind (https://nodejs.org/en/about/), which is why Node. js is considered an excellent option for HTTP servers.

Is Netflix still using Nodejs?

Netflix is now among companies using Node. JS due to the following reasons: A common language both for the server-side and browser side. High performance – now the page loads within seconds.

Which is better dot net or node JS?

Both the technologies have benefits and limitations, and choosing one depends largely on your project. ASP.NET is preferred by developers and enterprises for larger applications, whereas Node. js. is more suitable for fast, lightweight software and mobile applications.


2 Answers

The issue is that traditional web servers use a thread per socket approach to handling concurrent users which is not always optimal for comet/long polling techniques. (Newer versions of IIS have a way to plug in your own connection handlers however, which I will get too below.)

For the traditional web servers, more often the goal is to get a connection, serve the user up something as quick as possible, and move to the next connection. If a connection is lingering for a long time, its because its probably doing something intensive, like a big download or huge query but overall its actively using the CPU so the threaded model works pretty well.

In comet (long polling), normally you are connecting to a web server where you just wait for an event to occur, and more often than not. This promotes more concurrent connections. Also chacnes are that many of these users are waiting on the same events to occur across the board.

Allocating a thread then for a user to primarily just spin and wait is not a very optimal model for this type of thing. A better model is a event loop based web server that does everything in an asynchronous kind of fashion, and where dispatching off an event to multiple users doesn't involve a costly context switch for each client. This what Node.js is built on (using libevent as its core), as well as Ruby Eventmachine, Twisted Python, Friendfeed's Tornado, Jetty, and the C# based Manos server.

That is why there it's often more advantageous to have comet done on its own process custom a custom server since traditional web servers like Apache and older versions of IIS do not function in a matter that is efficient for Comet's needs.

Standard ASP.NET apps are little bit screwed because thread pool in .NET is limited to 25 general threads and 25 IO threads (and http connections take an IO thread). You may be effectively limited to be slightly less than that in reality because the thread pool is shared with all the other things in .NET. You can bump the thread pool up though with a configuration setting however, but performance has a tendency to decay exponentially the more threads you throw in. You could in theory bump this number up if you can guarantee you won't grow too much, and then possibly just use standard thread monitors in .NET to build your own comet event dispatching thing.

However .NET apps running newer versions of IIS do have a ray of hope though. You can create a custom IAsyncHttpHandler. There are some great guides online for you read up on how this works. With that you can build up your own connection pool and serve your clients more efficiently. It's not a perfect solution and you have to build out lot of plumbing on your own. WebSync is a commercial product that wraps this interface for you and gives you some high level framework pieces you can work with however.

like image 179
Zac Bowling Avatar answered Oct 03 '22 22:10

Zac Bowling


WebSync would be a good solution for you; it runs on IIS, so no external processes are needed. Check it out here.

like image 21
jvenema Avatar answered Oct 03 '22 23:10

jvenema