I need to write web aplication like google reader (using SmartGWT).
Instead of RSS feads I will show log files which updates in realtime. I think I can start a timer and ask server are there any new logs every minute. Is this the right way to do this?
Do I have to use WebSockets? Are they working in all the modern browsers?
I think I can start a timer and ask server are there any new logs every minute. Is this the right way to do this?
Without using server push this is the way to go. You typically want to query the server with the timestamp of the last received log entry. This way can you only send the diff since the last pull.
See here for some more information on GWT and push (which is actually pull). Or check out stream-hub (and the pimped stock watcher example) if you wanna go for server push.
Related
In implementing a browser-based simple game involving multiple users, I have the server save the game state at certain sync points (not time-based but event-specific). I identify each state by an integer.
When a user refreshes his browser, the server provides the latest state and restores the content in the browser. However, in those few seconds while the browser is loading the latest content after browser-refresh, the state could change again. I do not know how to handle this situation because sending the next state will again raise the same issue.
I want a seamless refresh so none of the other players are impacted when one user refreshes his browser (or for that matter leaves and comes back).
The implementation language is not relevant. I use websockets to communicate between the browser and the server. The server is the intermediary for all communication between users (I am not using WebRTC data channels). What is the best way to sync the application content in multiple browsers?
This is indeed a programming-based question though no code is provided.
Forget the fact that your client exists in a browser. Let's just talk about replication.
The usual approach in databases is to separate snapshots from Write Access Logging (WAL) logs. When you bring a new client up, you select a snapshot and transfer that. Then when the client is ready it asks for WAL logs from that snapshot forward. The same mechanism is used after crashes. The last available snapshot is loaded, then the WAL log is replayed, then the database comes up.
I would suggest the same strategy. This does require efficient storage of snapshots. Some kind of log. And some kind of replay mechanism. Which is a lot of easy to mess up code. If you can use something existing, that would be good.
The first thing that I looked into was using Emscripten to compile Redis to JS, and then try to use Redis' built-in asynchronous replication to replicate to your browser. That may be possible, but the fact that Redis is single-threaded and wants to be a client-server is probably a showstopper.
The next best option that I found is that you can use https://isomorphic-git.org/. Here is how that could build what you need. You simply maintain your current state in a git repository, and keep a WAL log of everything that you've done with it. When a client connects, it clones the repository. Once done it connects to the websocket, tells you what commit it is at, and you send it the WAL log from that point forward. Locally in the browser you run those git commands. If the client simply loses its connection and then rejoins, it can do a git pull, and then follow the same strategy.
This will be a bunch of work for you. But a lot less work than implementing everything from scratch.
This has been on my mind for a while now, and I guess I am asking it now. My question is how do live sessions work? For instance, a live chat session, or the live multi-user updater on JSfiddle.net. How do both items update instantly? In the case of the live chat, is it updating from AJAX to the server every second?
Sorry if my question is misunderstood, but my question is simply, how do live sessions work with multiple users?
EDIT
How does Stack Overflow do it? Every time something happens I get a notification, is that updating to the database every second to see if something happens, or is there a better (more efficient) way of going about doing this?
There is a couple of ways of doing it.
The most common way people are nowadays doing it is through websockets. You can just google that term and learn about it. Basically the webserver notifies you through a socket whenever it decides to.
Another way is polling. People used to do it like this back in the day. Polling is pretty much the dumb way: constantly (or every other second or so) sending an ajax request to the webserver asking if there is any new content.
Another interesting way is sending a get request that stays open for a certain amount of time, even after it gets a response. It sort of functions like a stream that you opened to a file or connection, it stays open untill you close it (or untill some other condition). I'm not too familiar with this method, but I know Google Drive uses it for it's multi-user file editing. Just open two sessions to the same Google Drive document and inspect the page. You'll see in the console that every time you type a block of text it'll send a post, and you'll have at least 1 get request pending at all times. At one point it'll close, and right away a new one starts.
So in short: Websockets, Polling, and whatever you call that last method.
Imagine an application which receives something like news updates every minute.
Would it be more efficient to build the server-side with something like Netty- which would maintain the connections and push the data once a minute, or something like nginx/php which would drop/open the connection each time a pull-request is made?
Each request would require a database lookup custom tailored to that user (i.e. no caching) and some basic processing (i.e. encryption/decryption)
?
Once every minute does not sound like it should put too much load on your infrastructure so I would say which ever way is easiest for you.
However, if capacity is an issue, I would say the push method is better because it will only send when there is data. The pull method will take up resources no matter if there is data to retrieve or not.
Hope this helps.
I have a django application in heroku and one thing I need to do sometimes that take a little bit of time is sending emails.
This is a typical use case of using workers. Heroku offers support for workers, but I have to leave them running all the time (or start and stop them manually), which is annoying.
I would like to use a one-off process to send every email. One possibility I first thought of was using IronWorker, since I thought that I could simply add the job to ironworker's queue and it would be exectuted with a mex of 15 min delay, which is ok for me.
The problem is that with ironworker, I need to put in a zip file all the modules and their dependencies in order to run the job, so in my email use case, as I use "EmailMultiAlternatives" from "django.core.mail.message", I would need to include all the django framework in my zip file in order to be able to use it.
According to this link, it's possible to add/remove workers from the app. Is it possible to start one-off processes from the app?
Does anyone has a better solution?
Thanks in advance
Ten updates a second, what would be the best way to do that? Aside from WebSockets (not fully implemented) what can accomplish this?
Would creating a Java Applet be worth it? Can you interact with the DOM in that fashion?
First 10 updates a second does not imply 10 messgaes a second to the browser, you can piggy-back updates to send one message a second (say) - no point in updates faster than the eye can see.
Commetd/Bayeuax worked for me.
Yes a JAVA Applet or any other Applet like Flex or Silverlight would be able to handle that speed.
As for the server side, I think you need a push server, you can't reach that rate of 10 responses / sec if each response is triggered by a client side polling request.
You you've got to let the flow of data come asynchronously from the server.
Examples of push server : Push Framework : http://www.pushframework.com