uWebSockets
github.com
github.com
I want the connections to be distributed to separate instances of a WS server based on modulo-based or consistent hashing algorithm... above that in the stack we have a message broker or queue partitioned using the same sharding algorithm for the number of websocket servers running. This queue/message broker sends publishes messages to each web socket service which in-turn pushes the message to the client. This is how I want to handle horizontally scalable web socket connections...
The question I have is the best way to do this and the best way to migrate connections. From one service to another when/if the replication factor of web socket servers changes (we add/remove servers)...
One way I would think would be to send a disconnect message to the websocket service when this event happens and it would disconnect it's clients and then have a random delay for when re-connection happens... so as to avoid trying to reinitialize all of those connections at once. This seems sub-optimal as with consistent-hashing many of the connections will stay on the same server, and terminating those connections would be unnecessary.
What is the best way to migrate an open TCP from one server to another? Or if the connection must be closed... how can we minimize the number of connections that are to be closed.
BTW: I know I can broadcasts to all instances of the websocket server, and then unless that server holds the connection it is no-op... if the server does have a connection then send the message back... This also seems it would have a limit to how far this scaling-strategy would grow before running into limitations.
That way, you can migrate users one by one (sending a 'redirectUserConnections(userId)' to the original server, and even pick a shard that is geographically close to the user. (If you care about race conditions during migrations, you need to be really careful though.)
race conditions during migrations are the biggest concern.... You do not want a client with a connection to server they will never receive a message on.
Can't you not involve the client and send it an explicit "reconnect to server XYZ" message, only move clients that really need to move?
haven't committed to using one particular technology. queues that support retries could be useful in the event that a disconnect happens messages wouldn't be necessarily lost. Something custom built on top of Redis could accomplish the same perhaps.
You're welcome to checkout the docs and get started: https://docs.hathora.dev/#/buildkit/README
If you'd like to get in touch, feel free to shoot me a message: sid [at] hathora.dev
Then you can use whatever logic you want for it. If the client disconnects, it just asks again and reconnects.
Use a token from the directory endpoint to authorize the connection so they have to do it.
[1] https://github.com/uNetworking/uWebSockets/discussions/1466#...
[1]: https://github.com/uNetworking/uWebSockets#battery-batteries...
It's common to remark on a language being "C-like"; not so much that a language is "JavaScript-like".
If someone made a web app in C++, it used to be OOP heavy. There's no class declaration in sight here.
You mean Lisp, and no surprise there, since JavaScript was supposed to be Scheme, except the commercial interests forced it to have Java-like syntax :).
[1] https://en.wikipedia.org/wiki/Clarke%27s_three_laws#Variants...
µWebSockets is a simple to use yet thoroughly optimized, standards compliant and secure implementation of WebSockets (and HTTP). It comes with built-in pub/sub support, URL routing, TLS 1.3, SNI, IPv6, permessage-deflate
I guess that it is a backend library for doing websocket communication for node and perhaps also bun?
https://github.com/uNetworking/uWebSockets/blob/master/misc/...
Interesting. Bun keeps getting more compelling.
Any binary library would also require building the library itself using the same toolchain and then linking to it - which requires a lot more configuration on the consuming side. It might be easy if both projects use the same build system (e.g. cmake), but that's far from guaranteed in C++.
If the library is open source, I'm fine compiling it once and then linking it. Not a big fan of header-only libs to be honest.
Addendum: though it is clearly a u in the URL. Someone may be confused...
μ provides a good contextual clue about the project. What would the ε character tell me?
Smaller than μ. Still strictly positive but as small as you want. Nothing possibly smaller.
That's epsilon, not ypsilon (it just occurred to me that it's more common to see it called "upsilon" in English, though I don't know why based on how the letter is pronounced - "eee-psilon")
> In the 1970s, programming was an elite's task. Today programming is done by uneducated "farmers" and as a result, the care for smart algorithms, memory usage, CPU-time usage and the like has dwindled in comparison.
https://github.com/uNetworking/uWebSockets/blob/master/misc/...
At what point does one assume moral high ground with 100% certainty?
It's as if all this hate comes from the inability to read text carefully, without isolating malicious intent first.
A "farmer" (note the double quotes) is a gaming/internet culture term that denotes someone who does repetitive, boring tasks in order to accumulate some kind of value.
I'm pretty certain that intelligent people who comment here are aware of it, but are using mental gymnastics in order to justify the insults they'll direct towards the author of microwebsockets.
Is that not hypocrisy in its finest form?
What is the cutoff date for terms we can use that won't confuse and emotionally outrage you?
‘What do you do for a job?’
‘I’m a farmer’
‘Oh right what’s the best quest to farm on in WOW?’
Said nobody ever.
It reads very poorly, in short.
Did you read the full context, or just rage at the cut out sentence that someone else here provided to you?
It's very clear in long form what he was talking about.
He has no control of people taking one sentence out of a long opinion that he has written.
It's up to you to inform yourself before joining the mob and sharpening your pitchfork.
Because they are not actually farmers, but have similar negative stereotypical traits?
Why are you so eager to accuse everyone of blind rage? I read the whole thing. It’s bog standard “these kids on my lawn” stuff which isn’t worth any brain power discussing.
However, you not being able to understand why people didn’t assign some convoluted meaning to the word farmer is quite interesting.
It has nothing to do with intelligence. I don't game. I don't consume media that would constantly expose me to gaming memes either. Mind you, I have heard of gold farmers in passing. Though when I read the word 'farmers' the definition I am familiar with is older than all of us put together. Nice try at an insult though.
b) Even if that's what the author meant, it is still a derogatory term when you consider its origin. Why do you think gaming culture picked "farmer" as the word used to describe someone who performs mindless repetitive tasks?
Question for you: where did that come from? Oh, that's right, by implication that actual real life farmers do repetitive boring tasks in order to accumulate some kind of value.
Your counterargument literally proves the point.
comparing software development (which, let's be honest, is super cushy) to farming is insulting.
I think farming is misunderstood because historically it's what 95% of people did, and it wasn't all that high tech. Not that pre-modern farming was easy: there's endless nuances about how to actually grow plants/animals optimally. But modern farming is ridiculously high tech. A modern farmer is a business owner, a logistics engineer, a mechanic, a programmer/hacker, and a labourer. I'm probably missing a dozen sub-professions of farmer. I bet "calories generated per farmer per year" would be a fascinating timeseries graph to view.
it's crazy good. small spoiler: it starts with jeremy buying a lamborghini tractor, because, well, it's a lambo!
at the end of the day, it made him respect farmers quite hard. and it showed a ton of people (including me!) how does modern farming works.
I mean you can be critical of communication forms without punching down.
Stephen Wolfram is going to be so pleased that he finally has his own unit named after him!
Mathematics, physics, computing, and now psychometrics, is there anything that man can’t make groundbreaking progress on?
“I don't know how many of you have ever met Dijkstra, but you probably know that arrogance in computer science is measured in nano-Dijkstras”
He's a bit like Linus. He knows what's up and sees all the people around him building sub par software.
But instead of telling them how to improve, he's very confrontative and I think those times of gatekeeping are over.
Gatekeeping implies that this author actually has something he can keep from you, like universities gatekeeping a certificate for intellectual credibility, or OpenAI saying that they have information that is too dangerous for the world. The personal refusal to acknowledge anyone for anything is only gatekeeping insofar as the public ought have some moral prerogative to that person's acknowledgment.
Why is this one author's acknowledgment so interesting that we should have a debate over it? In the face of all priorities, does this really bubble up to the top?
What's wrong with that statement? In 1970's, the number of people who dealt with programming was significantly smaller than today. It's a matter of fact. And people who worked with computers back then were highly educated and pioneers of the technology, there was no room for half-hearted effort or "let's copy the first result from stackoverflow.com".
Today, programmers who are meticulous, detail-oriented and who genuinely recognize the problem first are in minority and that's how I read the above.
The author might have stated it abruptly, but it does not mean he's wrong. You're using the "cool little library", yet you have this kind of resentment for the person who made it, have you even tried to look at the situation from their perspective before you passed the judgement?
I'm asking out of curiosity, because I can relate to having to work with under-skilled individuals who spend more time sorting out their CV and online presence than their work.
> under-skilled individuals who spend more time sorting out their CV and online presence than their work
That sounds more like a organizational/hiring problem.
It's not an insult in gaming context, and "farming" in the context of our craft does not relate to actual farmers. It sounds like taking things out of context to gain moral upper hand which allows for insulting the author.
I have to be devil's advocate, this whole shaming because someone else might have gotten offended is seriously tiresome.
Library is crafted well, guy's annoyed with self-proclaimed crappy devs, yet the freedom to say so is revoked by the very community he helps.
> 1. a person who farms; person who operates a farm or cultivates land.
> 2. Slang: Disparaging and Offensive. an unsophisticated or ignorant person, especially one from a rural area.
I'm saying this because I'm raised on a farm, I was always proud of it, I still do it as a hobby (and I love my crops) and I never, ever considered it an insult when I heard a term "farmer" or "peasant".
Nowadays, I read about people being offended in my stead, giving themselves the right to insult other people, like author of microwebsockets.
Is there a world in which haters could hate without using excuses such as "it insults farmers"?
I'm one of the farmers, I am not insulted, I do have the right to say this and point the attention at the *real* problem - and it's fake developers.
My most regular outburst of swearing is about 'dev-ops' and lack of engineering discipline and occurs almost daily :)
If you read the section, applying context from what the project is about and where it is used, you should pretty easily grasp the overall idea that is: "compression sucks and is incredibly inefficient". It would be a much more interesting thread if people took that message and argued against/for it, technically. But now we are here arguing about some word usage that might be offensive if interpreted in a very literal way. Congratulations; we have reached peak cancel culture. I hope you enjoy it while it lasts.
This isn't gaming. This is a programming library.
> It's not an insult in gaming context
This is not a "gaming context."
> and "farming" in the context of our craft does not relate to actual farmers
I've never heard anyone refer to "farming" in the context of programming. Please share with me more of the use of farming in the context of programming (not gaming).
> I have to be devil's advocate
This is a lie. You do not "have" to be devil's advocate. This was a choice you made.
> yet the freedom to say so is revoked by the very community he helps.
This is a lie.
Stop being a liar.
Finally, do not "revoke" my "freedom" to say this to you by disagreeing or arguing against me.
When I first heard of the term farmer/farming in-game, I didn't think anyone meant to point to any stereotypes either, just that the actual act had similarities with farming. Granted, in this sentence it's easier to interpret it the other way, but isn't it always better to give someone the benefit of the doubt? I can see how the process of programming lazily without understanding can resemble farming -and there might be a more intuitive metaphor if the author is not a native english speaker.
peace
And humans can be gamers and programmers. Welcome to real life, tutorial is now over.
> This is not a "gaming context."
When a word is placed in quotes, convention is that it has alternate meaning. I gave perspective, gaming is something that's socially well-known, along with its terms. Don't pretend you're unaware. Don't be a liar.
> I've never heard anyone refer to "farming" in the context of programming. Please share with me more of the use of farming in the context of programming (not gaming).
I won't.
> This is a lie. You do not "have" to be devil's advocate. This was a choice you made.
And these are mental gymnastics that you allow yourself so you can justify being rude. Don't be a liar.
> This is a lie.
> Stop being a liar.
Feel free to stop being a liar.
> Finally, do not "revoke" my "freedom" to say this to you by disagreeing or arguing against me.
I can assume you're accustomed to being invasive, rude and impolite but please, keep it for your inner circle of people. Or keep giving out orders to strangers from internet who will never interact with you after exchanging these words.
But what do I know ... I'm just a farmer. Now excuse me while I go shove my computer down a shredder and go do something else.
And yet probably the same percentage of what they wrote was utter crap [0]. The illusion comes from having more people writing more code for more reasons now. Sturgeon's law still applies.
On top of that, the industry rewards those who:
* "Produce results" insetad of those who pre-empted a bug 5 years in advance by building something to be robust [1].
* Job hop every year or two, and thereby disproportionately rewarding those who work on their CV.
* Are personal friends and family of higher ups [2].
To claim the major reason why software is in its current state is largely/solely because of all the "farmers" is harmful ignorance, at best.
> programmers who are meticulous, detail-oriented and who genuinely recognize the problem first are in minority
Perhaps the biggest problems in(/with) technology today aren't of a technical nature. If even somewhat true, then those who are "meticulously and genuinely recognizing the problems" aren't necessarily even programmers.
[0]: This is hard/impossible to know one way or the other due to survivorship bias. A lot of software from the 70s is just gone.
[1]: Instances of this are hard to even find, naturally. Squeaky wheel gets the grease and all that.
[2]: Hardly exclusive to IT, but still a significant factor.
Just ask the programmers back then; https://youtu.be/AxSdWhkMB_A
It sure does not sound like an elite career to me. It was just regular people working with the constraints they had at the time, not because of some super intelligence or leet genius focus on perfection.
If anything, projecting yourself (not you in particular!) into some mythical lost elite, as opposed to the current stupid pleb sounds like pure cope imo.
There is a very valid case to be made for the current state of performance but back then if it wasn't optimized for the resource constraints it didn't run -- nowadays software is optimized for shipping quickly so of course it sucks once the buzzword paint falls off.
We're comparing buy-once bespoke boots vs. assembly line fad-of-the-month trainers. The idea that either was the result of some 'giga brain' creators and not market influences is delusional.
We can instead spend our time doing really cool things with massive amounts of data, beyond the wildest dreams of the early coders.
The uWebSocket's authors take is SO bad in SO many other ways too. They should be prescribed a dose of real world.
"It's not bragging if you can back it up." - Muhammad Ali
Now I'm wondering if uWebSockets will fail spectacularly in 2038.
Much more offensive (to me) is this gem from later on:
> Designing clever, binary and minimally repetitive protocols saves enormous amounts of CPU-time otherwise lost to compression.
Well yes, but also, and more importantly no. This is technically true - not compressing the data is more efficient in terms of computation per bit on the wire. But it is also wrong in a much more subtle way.
The advantage of using JSON (or an equivalent) and then compressing it down is that we inject a large amount of redundancy into the format. The CPU is taking that redundancy back out for us to save bandwidth, but we get to exploit it in much more valuable ways. The encoder/decoder are generic, simple and highly optimized. We can use them everywhere and trust them to work. This has value in itself, and it means that we can spend our limited budget of programmer time in optimizing other code where the payoff is higher. It means less time tracking down bugs in "super 10x programmer's one-off encoder that was only written for this specific application". And lastly, but my favourite - it means that when something goes wrong we have a hope of repairing the damage to the data. Because redundancy gives us options for error checking and recovery, while optimizing the binary format generally does not.
Also, if you want the format to really be optimal it should not be designed as byte streams (as low-level binary formats generally are) and instead should be a stream of variable-sized tokens that are fed through an arithmetic encoder.
The first half of this week I spent repairing data corruption caused by some of my code. Luckily there is a lot of redundancy in how I encoded the data (in a structure that is described in JSON inside the records) so I could write a tool that repaired the damage. I guess I'm lucky that I'm just a "farmer" :)
I disagree strongly. Most people I encounter in the agricultural industry are quite creative lateral thinkers.
But yeah I guess they wouldn't think of higher lvl thought such as using JSON because it "helps" with corruption...good luck with your data