« first day (1892 days earlier)      last day (963 days later) » 
00:00 - 16:0016:00 - 00:00

12:00 AM
what I've written is what they've for the most part shown
including the boost examples
except the boost examples don't have an example for "broadcast a message to all connected clients simultaneously asynchronously"
 
There's multiple chat examples. They do that.
 
they do an "echo server"
 
yes - but the example doesn't show the broadcast to all clients
it just says "received message" -> send it back to the client
 
That's echo again.
 
12:05 AM
I want "send to all clients"
TCP
Async
it just seems really barebones
 
sorry it's just frustrating
 
There's not much point in repeating your claims at high frequency.
 
right - so I tried their chat example
(this was a few years ago)
 
:raises-brow:
You tried the example that they definitely didnt have :)
 
12:08 AM
I could not get the broadcast to go at high volume
 
Ah.
 
It worked - yes.
but as soon as you wanted a message larger than x bytes
or as soon as you wanted more than a few clients
it just couldn't handle it
 
What happened
I think I once tested that chat thing with many clients
 
the server slowed down and became unresponsive and the clients also became unresponsive
to the point the server just crashed
 
Ok
 
12:09 AM
due to the chat messages being too large
and having too many clients
 
Did it include printing to stdout?
 
initially, then I removed that part
since I don't really need to see it
 
@JoshMenzel Which was it :/ You seem to be naming all the suspects you can think of. We should want facts :)
@JoshMenzel Yeah, that would also be a huge bottleneck. Especially on windows
Wait. A tiny bopttleneck, more apt :)
 
their examples just don't suit what I'm trying to accomplish
and without documentation or comments in the code I can't make heads or tails of why things are the way they are in the example
 
Oh dang. I see what happened. I ran clang-tidy on the code and it broke all those bind expressions into broken lambda expressions. That explains.
19 mins ago, by sehe
How? It's not valid code.
 
12:14 AM
oh
lol
 
So, that was a false alert
 
yeah that would explain a lot
 
I'm gobsmacked. I had no idea that clang-tidy would do that
I'm shook :)
 
did it think the bind expressions weren't necessary?
 
It thought it knew how to morph them into lambda expressions. Which ... can be done, just not how the transformation was applied
 
12:16 AM
LOL
That's fantastic
 
Very helpful tool
I have had a beef with clang-modernize once but it was ~5 years ago. I sort of trusted clang-tidy
 
Sorry to break that trust
xD
 
Not your fault
 
So the code is fine right?
or am I still using boost bind incorrectly
 
It did compile. Still reviewing the surface, But lost considerable time on that stupid mishap
@JoshMenzel Nah those were fine
 
12:20 AM
breathes sigh of relief thank goodness I'm not crazy
was gonna say was ready to lose my mind
@sehe
oops sorry - was gonna ask if there's anything you've found
 
I'm reading. And going to bed soon
 
now that you're looking at valid code xD
ah
to be continued another day perhaps?
 
Depending on what I find
 
12:35 AM
This has just got me scratching my head
Because game servers have to handle the same thing
 
It's almost like there's an actual craft to it.
 
well like I said I primarily do C#/.NET and higher level stuff
 
Then it's bound to be intimidating
 
it's been massively intimidating
memory leaks left and right
pointers not clearing
threads not syncronizing
it's been a nightmare
I'm surprised I got this far
I'm hoping I'm just dumb and that it's something obvious
I'm just trying to further my abilities
 
And you're doing it. For many people, this is the best way to learn.
See the many tutorials titled "Learning XYZ the hard way"
 
12:45 AM
yeppers
 
believe me, I've been there
It's been a while, so it's easy to forget. But the angst is real.
 
I guess I don't know what further optimizations I can make
I just don't know what else to try
went through the same thing for c#/.NET
not for this type of work
or concept/scenario
 
@JoshMenzel One big one has already been pointed out: use UDP. Order really isn't a problem on localhost, but if you're really concerned about that use a library that supported ordering over UDP (but will still support broadcast). For one example, I've used enet with good results. I'm not sure it supports broadcast though--I've used it for mostly TCP-like connections.
 
@JerryCoffin I want to get this to work on TCP because I need to know what I'm doing wrong
If I'm not using the callbacks, handlers, etc... correctly
then I need to know
 
@JoshMenzel Given that you want to broadcast to hundreds of clients, there's quite a fair argument that one of the things you're doing wrong is using TCP.
 
12:55 AM
and I don't disagree - but I want this to be general purpose
so if say tomorrow I wanted to make a chat server
and have 200 people on the chat server
or 1k people on the chat server
I want to be in a position to understand how to do that
so removing the strand from the write on the server reduced the times to 6-20ms to do the broadcast message
also I should warn you on the client @sehe it's very RAM intensive
 
What platform are you targeting?
 
all of 'em
2 hours ago, by Josh Menzel
Windows, Linux and Mac OS X
 
Well ok I can help with Windows - just use winsock and Schannel and it should be fast enough.
 
1:19 AM
Yeah unfortunately it's up to how asio handles it
 
Which is roughly that, I suspect.
 
I would suspect that as well
I should be able to run it in debug mode and not have any delays right?
like I shouldn't have to put it into release mode
 
Depends on what optimizations you disable in debug mode, and what asserts are being enabled
 
1:38 AM
@sehe part of it is I'm a dumb****
 
Is there anything you want to tellme?
 
maybe...
 
Generating random messages using string concat is not optimal :)
 
Line 303 in Connection.h
I call pop_front in WriteHeader
twice
 
Oh interesting.
That helps crash earlier sometimes
 
1:39 AM
but that still didn't solve the latency
 
Of course not. It's only incorrect
 
1:53 AM
also whatever issue with sending at once is gone
 
I wonder how you "send at once"
I was thinking scatter/gather
So I basically have a rough idea of what the code does now.
I'm not sure I should inflict this on you yet...
 
2:11 AM
I saw that term mentioned too
was wondering what that was
@sehe
 
I'll explain when you say how you "send at once" now :)
 
ah okay
 
Well. Past me already explained a bit
1
A: Boost ASIO slow

seheFirst off, without measurements you're nowhere. Can you prove that it is unnecessarily slow? Second, be sure to use scatter-gather and the composed write-operations supplied by ASIO. That eliminates your code as a source of inefficiency, and also generally removes room for error. In that case ...

 
I do a vector of boost::asio::streambuf::mutable_buffers_type
then build the header buffer push it to the vector, build the body buffer and push it to the vector
then give the vector as the buffers to async_write
@sehe so I'm doing exactly what the guy is doing
makes sense
I don't understand your answer though
 
@JoshMenzel That's scatter/gather alright
@JoshMenzel Well. Seems you find out things quickly using other sources, so no biggie :)
 
2:17 AM
But I'm still seeing that latency
 
Okay. Let me share you my scribblings for now. It's 4:xxam here
 
sure - I do appreciate the help
 
@JoshMenzel gist.github.com/sehe/a32a59096279d5fef99c9824a6da0168 See you around tomorrow? @sehe ping me if you need my attention
 
@sehe we'll see - it's 9PM here so plenty of time to look this over
 
You can disregard the CMakeLists.txt - it's literally a copy of a file that I've carried for years answering SO stuff. It's a mess of irrelevant things
 
2:22 AM
Thank you so much!
 
Cheers
The executor refactor is not done - it's still effectively the same
 
ah
does this pass the 200 concurrent connections test?
I should find out
was wondering about how to get the pointers to move
 
2:43 AM
I'm a bit confused about the enable_shared_from_this. Best I know it only works with make_shared`. And it cannot be used because the constructor is private. How does that work on your end?
 
2:55 AM
I honestly have no idea
it just does work
if I use this->shared_from_this() I'm fine
I think that's why I did that
Like I said I have no clue HOW any of it worked
@sehe
Though I am a bit lost on the Executor part
 
good to know
Yeah I can't get the templates for the callback types to play nice
 
3:45 AM
So when do I need to use std::move @sehe?
if I want to pass this->shared_from_this() to a function, do I have to pass it as function(arg1,std::move(this->shared_from_this())?
 
Nope. It's never needed/useful on temporaries. The return value of shared_from_this() is one (what's known as rvalue in the inscrutable standards jargon)
Looks like I'm going to be proven right about that:
2 hours ago, by sehe
Generating random messages using string concat is not optimal :)
 
4:21 AM
Yeah I'm having trouble getting the templates to be decent
 
5:06 AM
I've gotten everything except for the boost::bind
it doesn't like it
 
5:40 AM
https://stackoverflow.com/questions/52371051/visual-studio-callback-function-problem-cdecl
@sehe I have this exact issue with the connection create method
 
6:39 AM
It refuses to build in visual studio MSVC
even though it's cross platform - it needs to build in MSVC with __cdecl
 
6:49 AM
@JerryCoffin yeah, I get that and I was looking for the mechanism/timeout by which it would still send smaller packets and the wiki page said it was when it received the ACKs for all previous packets
 
 
1 hour later…
7:57 AM
finally got it
 
@JoshMenzel was this a 32-bit application? I thought microsoft fixed most of the calling convention issues on the 64-bit ABI
 
no the bind placeholders didn't match the function signature
because I was an idiot and changed it
why can't it just say boost::bind parameters do not match function signature
instead of cannot convert R to __cdecl(&R) in bind.hpp
https://gyazo.com/255a41ba9b4b7a7f7c2a1f5d4ef75319
That's where I'm calling it for tonight
@sehe
each one of those client-test windows is 50 clients
 
8:30 AM
@JoshMenzel do you have to use bind? is there a reason you can't use lambda capture lists?
 
9:16 AM
Has anybody ever used asio( not Boost::asio, which is not depend on Boost)?
The compiler complains that "error: ‘deadline_timer’ in namespace ‘asio’ does not name a type" when encounters using deadline_timer = asio::deadline_timer;.
 
yep, I've used it like 2 years ago with cpp-netlib I think
sounds like you just forgot an include with that error message
 
 
2 hours later…
11:31 AM
@PeterT most and then they added a new calling convention back to x64
 
@John it used to be in its own include, but maybe it was superseded by e.g . high_resolution_timer/steady_timer
 
 
1 hour later…
1:00 PM
How would one define an array of fixed size 2d array? Something like double* arr_of_boxes[2][3]?
 
1 message moved from Lounge<C++>
@Eminem pretty much, but I suspect most people would say to avoid that as it has a lot of weird non-intuitive corner cases
 
1:41 PM
@PeterT I guess I'm not sure what the difference is
 
in most cases lambdas can be optimized out or at least severely. bind has a lot of overhead that is obsolete with lambdas and captures
 
Was bind created before lamdas?
I guess how would I change it to be a lambda
 
nwp
I recommend you forget that std::bind ever existed.
 
boost::bind<void>(&Server<MsgId, Executor>::message_sent, this, boost::placeholders::_1, boost::placeholders::_2);
how would I turn that into a lambda with the parameters (placeholders)
 
nwp
I can't even read that properly.
 
1:50 PM
basically it just needs to call this->message_sent(this->shared_from_this,message)
 
@JoshMenzel [&Server<MsgId, Executor>::message_sent, this]{ // do stuff }
yeah you don't even need the parameters
 
nwp
[this](Message message) { message_sent(shared_from_this, message); } probably.
 
but I do?
oh yeah
 
why? you're capturing
 
yeah I need the capture
lol
 
1:52 PM
The capture is what allows lambdas to replace bind
 
yeah that isn't gonna work
the binding is passed as a parameter
auto new_connection = conn_ptr::create(arg1,arg2,binding1,binding2,binding3)
and new_connection is the 2nd parameter
 
you're probably making things too complicated?
 
auto binding1 = boost::bind<void>(&Server<MsgId, Executor>::client_message, this, boost::placeholders::_1, boost::placeholders::_2);
auto new_connection =
conn_t<MsgId, Executor>::create(this->acceptor_.get_executor(),std::move(s), id,
binding1,
binding2,
binding3
);
so new_connection would need to be one of the captures
 
nwp
Can you show the whole function? I'm sure there is a straightforward way to use lambdas.
 
Impopular opinion: getting rid of std::bind for the sake of it isn't worth the effort here.
 
2:00 PM
if it was std::bind I might agree, but it's boost::bind which is even less necessary
 
At this point there's really no discernable difference.
There's lots to be refactored, and this ain't the most important thing (I'm working on it btw)
 
fair
 
Still good to remember that bind and friends are usually unnecessary, and rarely more readable (exceptions certainly exist)
 
@sehe I actually ended up removing owned message
and the owner enum
 
@JoshMenzel Hey, you too :)
Just pushed my server work-in-progress
https://gist.github.com/sehe/a32a59096279d5fef99c9824a6da0168
> 10 files changed, 685 insertions(+), 1059 deletions(-)
@JoshMenzel It lead to a load of unnecessary copying. There's LOTS of room for optimization still, but I've been simplifying the code first
 
2:09 PM
Ah the classic "the code that doesn't exist shouldn't slow you down"
 
@sehe yeah
I also removed the signals stuff too
 
All of it? I can see that "broadcast connection" being error prone & redundant. Did you instead give the connection a reference to the server?
 
no the connection has no reference to the server
that's what the boost::binding calls are for
in the create
 
Ah, you just replaced the slots with singleton calleables
 
and then I use std::for_each
 
2:20 PM
(As a rule, when you have a group of related calleables, that could be a virtual interface. It smells like it should be here)
@JoshMenzel Why. Ranged for is fine
 
IMO std::for_each has even less reason to exist anymore than std::bind
it adds function call overhead where none is needed
 
In fairness, it probably doesn't due to inlining, but why bet on the complicated route
 
@sehe parallel processing
It's still taking that 10ms to iterate
 
That's benchmarking the wrong thing, surely.
 
@JoshMenzel threads are expensive yo...
 
2:26 PM
 
I mean I do tStart ... for(){} tStop
 
Quick test with 1,000 and 5,000 concurrent connections. The clients only read
 
that's what takes 10ms
 
I got that
This is the throughput for that:
Compare:
15 hours ago, by sehe
Not really. That's a meager ~500 mebibytes per second
Now let me find some bottlenecks
 
Hello! I ran cppcheck on our code and it hinted that 'EmbeddedResourceAccessor' forward declaration not expected in source file; here is the code (I'm not the one who wrote it). This line does not seem to be needed as commenting it out gets me the same behaviour. Is there a point in instancing the class like that, or is it really only a forward declaration and not an actual instantiation?
// Convenience typedef to reduce typing.
typedef EmbeddedResourceAccessor<SilverLiningResources> SimSilverDataAccessor;

// !!! IMPORTANT !!! Create the accessor methods by explicitly instantiating the template class.
template class EmbeddedResourceAccessor<SilverLiningResources>;
(It's the last line.)
 
2:31 PM
It's typically important. But it's well possible that all the implementation details that you actually rely upon are in the header file. For now.
 
Thanks; I read on that page that the functions that are never used are never instantiated, so is the comment "right" when it says "Create the accessor methods"?
 
It prbably is. But we can't tell withut the cde
Wow. My o key just casually stopped working there
 
I found it funny ;)
 
I'm keeping it :)
 
@Vaillancourt IIF they aren't inline in the template, it's a weird quirk IIRC
 
2:41 PM
It could even be "redundant" but just to make sure that the TU exercises the templates (to diagnose 2phase errors early?)
 
Okay, thanks to both of you; I'll keep it there with an additional note.
 
@sehe so am I measuring my clients wrong then?
 
More like you're focusing on a less-than-relevant point? Use a profiler to see where time is spent
 
is there a similar tool I can use on windows?
to simulate the clients?
 
if Sehe is using netcat.... that already exists for windows
 
2:56 PM
the concern is that
if the broadcast takes more than the interval
and it takes the clients longer than the interval to receive and process the messages
then the client will never catch up
10 broadcast messages at 50ms intervals but the client only actually receives 1 every 60ms
creates a backlog
 
There's a difference between latency (think lag) and bandwidth (think streaming velocity)
You are right to also wish to minimize the latency, but there's only a problem when the latency is more than you can buffer for, (or your results become useless for external reasons)
Still, the steps are: identify bottlenecks, identify fixes, select high impact low effort wins, impolement top-N
 
if you're using networking, you need to be fault tolerant anyway. What happens if a packet is dropped?
 
Right now whatever a client gets is random. So I guess it's all in the phase of academic exercise
@JoshMenzel my scratch area for today imgur.com/a/3SP6B7Z in case you want to see how I measure/what I measured until now
 
so then how can I write a client that doesn't have to buffer?
or have a backlog?
if it's not latency on ASIO's part on the server side
 
There's always latency. The point is whether you care/can deal. Latency is not an issue, unless there is a throughput mismatch. That is unlikely to happen in this case
37 mins ago, by sehe
15 hours ago, by sehe
Not really. That's a meager ~500 mebibytes per second
 
3:09 PM
so I guess the server is fine
it's just the clients that have to be able to keep up
then?
 
You can and should still optimize, but it's not a dead end.
 
I mean if I try to do 1k clients with netcat on my windows dev machine
the broadcasts take hundreds of milliseconds
 
Point in case, just pushing these changes: gist.github.com/sehe/a32a59096279d5fef99c9824a6da0168
 
so I can't replicate your results
 
All it does is avoid copying messages, and it reduces time spent in memcpy from 77% of total time to 4%
@JoshMenzel Patience. I'll also give that client code a look, but one step at a time.
 
3:13 PM
well I did download netcat for windows
so I can simulate similar things
 
I'm actually quite slow working, but my experience gives me the magic productivity boost
@JoshMenzel :thumbs-up:
 
but that's why I'm saying I can't replicate the results - also mind if I re-upload the most recent thing I'm working off of
 
I don't mind, but I won't look at it much (if at all), because that's not the point of my review/refactors. The point is to reduce clutter so you can be enlightened just reading it :)
It's a lofty goal, but I think it's achievable
 
ah - just more for efficiency
but yeah doing it this way I can see what changes are made then integrate them onto the solution I'm working out of
the only other thing I did was do all the templates and names in the prerequisites
 
I realize that you're doing parallel / double work, but I think that's what you want, because it allows you to actively learn the details?
 
3:17 PM
@sehe yeah now that I think about it yes
 
@JoshMenzel Precisely
 
So why is a shared_ptr better than using the & symbol
I thought the & symbol was pass by reference
 
Share pointers aren't better.
Shared pointers are usually quite dubious, in fact. However, here it is the clearest way to extend the lifetime of the message(s) for as long as some remote is still having it queued (or actually resends it!)
@JoshMenzel Yup. And it's usually superior. What shared_ptr solves is NOT the passing style, but the lifetime semantics.
 
I just remember having terrible problems with memory leaks and shared_ptr's
 
You can pass around references, but when do you get to clean up the instances?
 
3:20 PM
I put it on the responsibility of the caller
(as is the case in c#)
 
@JoshMenzel That's possible (only) with cycles. That's actually the kind of leaks you will also recognize from C# or Java
 
(though c# handles this automagically)
 
I think that C# eventually catches cycles, but you can easily leak if some collection still contains a root for such a cyclic graph
Regardless, yes, this is another possible improvement: e.g. making the connection map contain weak pointers and getting rid of all explicit locking. Though you would get more strand executions as a trade off. I'm not sure it's a big win, but I might try it
 
C# can have some weird quirks for high throughput stuff
I remember my roommate in college spent his entire internship optimizing stuff in sharepoint server to not allocate memory so they could avoid GCs
Linq... lol no that allocates, ranged for loops? NOPE those allocate
 
Exactly
I did notice that
 
3:25 PM
for the vast majority of code it's not an issue TBF
 
That's why I'm not trying to do this inc#
 
buuut if you have a super hot path that's constantly getting called it can be an issue
also TBF the C# and .net folks are trying to fix a lot of that in new versions
 
What's funny is that with that last change, WriteMessage up in total %, but in absolute time it went down :) i.imgur.com/jva3oLM.png
 
such is the life of profiling
 
It just proves that you "hit the bottleneck", because now something else becomes the bottle-neck
 
3:28 PM
So I guess I'm lost as to the changes made
 
Time to be cooking. bbl
@JoshMenzel You can view per-commit
Do you know how to clone a gist locally? Then you can just use regular Git tooling
It's well hidden. I installed gh command line tool yesterday just so I don't have to keep looking it up (then it's something like` gh gist clone a2c54169d35915f2a102533850123920`)
 
@sehe actually no I don't - I have git installed as well as various other tools for it
 
It's worth a google. I do this because I don't deal well with GUIs
 
3:49 PM
I'll have to integrate the changes later today
there's just been such a struggle with how c++ works
is a shared_ptr guaranteed to be deleted automatically
 
@JoshMenzel so C++ is what I'd call a resource oriented language where scope matters. When something leaves scope the destructor is run. So insofar as you're using shared_ptr correctly... yes it will auto cleanup
 
right so if I do something like

auto ptr = boost::make_shared(something);

auto mynewthing = new thing(ptr);

what happens to ptr?
does mynewthing now own a copy of ptr
 
ptr gets cleaned up at scope exit (also use std::make_shared not boost
depends on what mynewthing does in its constructor... either way avoid raw new and delete
 
but mainly when new thing has some background work to do that uses ptr
is a copy of ptr made
so it stays valid?
 
so shared_ptr as the name implies has a reference count
internally every copy of that shared_ptr references the same control block
the control block keeps a count of the number of strong owners and weak owners
if the number of strong owners goes to zero it deallocates
 
3:55 PM
that leads me to my next thing - how is weak_ptr different?
and what constitutes strong vs weak
ie. when should I use
 
weak_ptr doesn't own, it just may need to occasionally grab a strong reference to use it
 
does weak_ptr go out of scope and get deallocated automatically the same as shared_ptr?
 
basically the idea is that a weak pointer will say "HEY I need to use this for a sec" grab a strong reference so it can't be deleted on it. Then release that as soon as it's done
you're testing my pedantry...
there is a difference between the thing the weak/strong ptr points to and the ptr itself
 
lol it's just nothing explains these things really well
 
the ptr is just a tool that holds onto a reference to the thing
and then does something at scope exit
 
3:58 PM
okay
 
so for example new std::strong_ptr<foo> is always wrong
but std::shared_ptr<foo> bar = std::make_shared<foo>(); is right
because the shared_ptr needs to be an automatic variable that is deallocated when it goes out of scope
the foo that it points to... is not, that is a dynamic variable that needs to be deallocated when all the things pointing to it... go out of scope
 
00:00 - 16:0016:00 - 00:00

« first day (1892 days earlier)      last day (963 days later) »