Re:Show HN: Real Time Users – Add a real-time user counter t...
by nevi-me on Thursday June 09, 2016 @12:47PM
(#11870567)
Why not just use websockets? I use socket.io on my site. I keep track of socket IDs in memory, if a connection is lost, I get a disconnect event, and vice versa. Socket events are sent to users when the number changes.
I manage the frequency of socket emits using RxJS, to prevent sending too many changes to users.
Re:Show HN: Real Time Users – Add a real-time user counter t...
by simplify on Thursday June 09, 2016 @08:43PM
(#11873480)
Websockets would overkill for this kind of feature – you don't need realtime two-way communication. Server sent events (SSE) [1] are a much better alternative; it's a simple, long-lived HTTP request where the server can push data to the client. They're built into most browsers [2], and the client-side polyfill [3] is small (2kb gzipped).
Re:Show HN: Real Time Users – Add a real-time user counter t...
by nevi-me on Thursday June 09, 2016 @11:39PM
(#11874141)
Fair enough, but what happens if I open a page, send an Ajax call to say "add 1 user", then promptly close that page? I don't know what OP is doing to detect that a user is no longer on the site.
The reasons why I used WebSockets are that I get a disconnect event immediately, and I was already using WebSockets for other features on the site
Re:Show HN: Real Time Users – Add a real-time user counter t...
by simplify on Friday June 10, 2016 @02:38PM
(#11878797)
It's a long-lived HTTP request. The server automatically knows if a client disconnects; that's a feature built into all HTTP server libraries everywhere.
But yes, if you're already using websockets for other features, there's no reason not to continue to use them, as you explained :)
Re:Show HN: Real Time Users – Add a real-time user counter t...
by WWKong on Thursday June 09, 2016 @08:05PM
(#11873326)
Can I get your help in deploying socket.io to Google App Engine? Is it possible? It works locally for me but Google app engine seems to close out the websocket.
Re:Show HN: Real Time Users – Add a real-time user counter t...
by subie on Thursday June 09, 2016 @11:52AM
(#11870200)
Is using ajax calls on a loop the best way to track users on a site? I'm curious because when I look at pages using google analytics I don't see any repeating requests in the network console. Does google mask the requests or use some other protocol?
Re:Show HN: Real Time Users – Add a real-time user counter t...
by mikeaag on Thursday June 09, 2016 @12:07PM
(#11870296)
Hey subie,
I'm one of the creators of Real Time Users.
Only 1 AJAX call get sent to 'track' you on the site for each page load. The AJAX calls you're seeing are asking the server for the latest number of users on the site so that we can update the value displayed.
This isnt the most efficient way of doing this, as if the site has a low number of users, the count will return the same number most of the time. A better way would be to use websockets, however i only have limited knowledge of using websockets so we decided it was best to just stick to the tech we knew (Especially as we built it in a weekend).
If people start using this more, we might update it to use websockets though.
Hope that answers your questions. Let me know if theres anything else you'd like to know.
Re:Show HN: Real Time Users – Add a real-time user counter t...
by nevi-me on Thursday June 09, 2016 @12:51PM
(#11870588)
I commented separately, I use sockets for this. I don't know about libraries for PHP as I haven't used it in a while, but most socket libraries make it easy to implement something.
My implementation is in-memory, and the nice thing about it is that if fit example my Node.js app restarts, all active users will get disconnected, and they will emit a connection event, allowing me to get the count of online users again.
I can extract relevant code and share it if it'd help.
Re:Show HN: Real Time Users – Add a real-time user counter t...
by mikeaag on Thursday June 09, 2016 @01:12PM
(#11870736)
Hi Nevi-me
I've come across Socket.io before, and played around with pusher as well. And if i remember correctly, Laravel has built in helpers for sending websocket messages.
My main issue is actually running the node.js application, as its something i've not done before. That was another reason for not using websockets. Wanted to remove as many barriers that might slow us down or stop us from launching, so we stuck with what we knew.
I'm sure i'll update this at some point to use websockets though, gotta learn how to deploy node.js sites at some point :D
Re:Show HN: Real Time Users – Add a real-time user counter t...
by subie on Thursday June 09, 2016 @12:43PM
(#11870541)
Ohh I didn't even look in depth at the request. Thanks for the response!
I'd say ajax is probably the right way as far as polling for the data goes. Using web sockets for polling incredibly simple data doesn't seem necessary.
Re:Show HN: Real Time Users – Add a real-time user counter t...
by mikeaag on Thursday June 09, 2016 @12:56PM
(#11870629)
The benefit of using websockets is that each user's browser doesnt need to constantly be requesting the number of users from our server. If the number of users on the site hasnt changed, then with AJAX polling, its a wasted request. But with websockets there is no waste, the client gets pushed the updates when they happen from the server.
Having said all that, with the number of requests that we're getting at the moment, i dont think it makes much of a difference. Though im guessing if we got a lot more traffic, then websockets would probably reduce our server load.
Re:Show HN: Real Time Users – Add a real-time user counter t...
by fredrivett on Thursday June 09, 2016 @06:14PM
(#11872778)
It's currently unique visitors. So, if you refresh the page, it doesn't increment the counter, as it knows you've already been logged. So it's visitors, rather than visits.
Re:Show HN: Real Time Users – Add a real-time user counter t...
by fredrivett on Thursday June 09, 2016 @06:15PM
(#11872783)
Haha yep! Its a cool idea. Marc's got a good network though, which helps when you're starting out with a product like that. Gotta avoid the tumbleweed effect at all costs.
Re:Show HN: Real Time Users – Add a real-time user counter t...
by fredrivett on Thursday June 09, 2016 @07:57AM
(#11868780)
Hey all.
Last week Marc Kohlbrugge launched https://highscore.money/. Following that, he sent out a tweet, asking if anyone knew of a good real time user counter to add to his site.
Re:Show HN: Real Time Users – Add a real-time user counter t...
by fredrivett on Thursday June 09, 2016 @11:52AM
(#11870202)
I think there's room for adding style around substance, but not if it causes issues. I wasn't aware of the performance issues, but now I know I'll be sure to look at this when I get home from work.
People are allowed to make things even when other things like that already exist, and they're welcome to share them here. The spirit of Show HN is "hey, I made this," not, "I declare a claim to priority".
A better way to post a comment like this would be to mention specific other projects in the space and ask how this one differs.
Re:Show HN: Real Time Users – Add a real-time user counter t...
by fredrivett on Thursday June 09, 2016 @10:14AM
(#11869490)
There's nearly always existing solutions to problems. From my experience, if they're not well known enough, that's a good enough reason to build something. There's still space in that area.
For us, this was just a fun hackathon over the weekend. But who knows where it will go, maybe we'll continue developing it out and it'll become something more. We'll see.
Re:Show HN: Real Time Users – Add a real-time user counter t...
by colinbartlett on Thursday June 09, 2016 @11:39AM
(#11870098)
It's very frustrating to me when people here take the time to build something and then solicit feedback from HN, only to have someone immediately post "That already exists".
Sure, it can be nice to solicit explanations of differentiation from the OP to help understand the use cases, but these kind of sweeping comments aren't helpful to anyone.
Re:Show HN: Real Time Users – Add a real-time user counter t...
by fredrivett on Thursday June 09, 2016 @11:49AM
(#11870183)
I think there's some value to see other options solving a similar problem, but I agree the "that already exists" mantra is pretty limited.
For a long time we never shipped anything due to the need to try and make the next Facebook in one go. It crippled our creativity.
These days we've learnt that it's ok to build and launch something that's been done before, the most important thing is learning to launch. For us we launched this to get back into the swing of launching stuff after a few months since our last launch. This is entirely an MVP, built and launched in under 15 hours total design/dev time.
Re:Show HN: Real Time Users – Add a real-time user counter t...
by oneeyedpigeon on Thursday June 09, 2016 @02:01PM
(#11871115)
The trouble is, you didn't say any of that in your original comment, so it was easier to misunderstand your intentions than not. OP is probably aware of the alternatives, but somewhere along the line, none of them fulfil all their requirements.
I manage the frequency of socket emits using RxJS, to prevent sending too many changes to users.
https://movinggauteng.co.za, there's a counter at the top of the page.
EDIT: Only saw a comment about why the OP used Ajax after posting this.
[1] https://developer.mozilla.org/en-US/docs/Web/API/Server-sent...
[2] http://caniuse.com/#search=server-sent%20events
[3] https://github.com/Yaffle/EventSource
The reasons why I used WebSockets are that I get a disconnect event immediately, and I was already using WebSockets for other features on the site
But yes, if you're already using websockets for other features, there's no reason not to continue to use them, as you explained :)
http://stackoverflow.com/questions/37401250/how-do-i-deploy-...
I'm one of the creators of Real Time Users.
Only 1 AJAX call get sent to 'track' you on the site for each page load. The AJAX calls you're seeing are asking the server for the latest number of users on the site so that we can update the value displayed.
This isnt the most efficient way of doing this, as if the site has a low number of users, the count will return the same number most of the time. A better way would be to use websockets, however i only have limited knowledge of using websockets so we decided it was best to just stick to the tech we knew (Especially as we built it in a weekend).
If people start using this more, we might update it to use websockets though.
Hope that answers your questions. Let me know if theres anything else you'd like to know.
My implementation is in-memory, and the nice thing about it is that if fit example my Node.js app restarts, all active users will get disconnected, and they will emit a connection event, allowing me to get the count of online users again.
I can extract relevant code and share it if it'd help.
I've come across Socket.io before, and played around with pusher as well. And if i remember correctly, Laravel has built in helpers for sending websocket messages.
My main issue is actually running the node.js application, as its something i've not done before. That was another reason for not using websockets. Wanted to remove as many barriers that might slow us down or stop us from launching, so we stuck with what we knew.
I'm sure i'll update this at some point to use websockets though, gotta learn how to deploy node.js sites at some point :D
I'd say ajax is probably the right way as far as polling for the data goes. Using web sockets for polling incredibly simple data doesn't seem necessary.
Having said all that, with the number of requests that we're getting at the moment, i dont think it makes much of a difference. Though im guessing if we got a lot more traffic, then websockets would probably reduce our server load.
Who knows whether anyone will actually use it.
There's also a leaderboard, to track who does.
https://realtimeusers.bycontrast.co/leaderboard
Just like the million dollar homepage guy - why didn't I think of that!?
Last week Marc Kohlbrugge launched https://highscore.money/. Following that, he sent out a tweet, asking if anyone knew of a good real time user counter to add to his site.
https://twitter.com/marckohlbrugge/status/737388891246891008
No-one did, so we made one.
Real Time Users is just that. We made it this weekend. I wrote a quick post introducing it, so feel free to look at that for more details.
https://blog.wearecontrast.com/make-stuff-ff82f78cf5a9#.s8mg...
Feel free to ask any questions, I'll be about all day.
You could read this ( I just duckduckgoed this, but it looked like what I remember it involves to do this).
http://blog.teamtreehouse.com/increase-your-sites-performanc...
https://blog.wearecontrast.com/
Let me know if theres anything else you'd like to know
https://www.google.com/search?q=user+counter brings many websites offering this in various fonts, sizes and colors.
But then again, 'good' can be very subjective...
Please don't be dismissive of new work on HN, especially in Show HNs: https://news.ycombinator.com/showhn.html.
People are allowed to make things even when other things like that already exist, and they're welcome to share them here. The spirit of Show HN is "hey, I made this," not, "I declare a claim to priority".
A better way to post a comment like this would be to mention specific other projects in the space and ask how this one differs.
For us, this was just a fun hackathon over the weekend. But who knows where it will go, maybe we'll continue developing it out and it'll become something more. We'll see.
You are right though! :)
Sure, it can be nice to solicit explanations of differentiation from the OP to help understand the use cases, but these kind of sweeping comments aren't helpful to anyone.
For a long time we never shipped anything due to the need to try and make the next Facebook in one go. It crippled our creativity.
These days we've learnt that it's ok to build and launch something that's been done before, the most important thing is learning to launch. For us we launched this to get back into the swing of launching stuff after a few months since our last launch. This is entirely an MVP, built and launched in under 15 hours total design/dev time.
Thanks for taking the time to comment Colin.
I think its always good to do some fact checking...