
Memory usage of a toy C# server and client with 500K concurrent connections on - pplonski86
https://github.com/kjpgit/techdemo/blob/master/dotnet_client_server/README.md
======
me551ah
C# is a pretty underrated language. I've worked with JS, Java, C++, Perl and
I've always preferred to use C# for personal projects.

async/await - C# is the ONLY language which gets this right. Javascript has it
now but you need to be use libraries which support it too, which are hard to
find. Kotlin has coroutines but Java base library doesn't have support for
coroutines so you can't use it all the way through and create a chain of all
async functions. Once you use async/await it's hard to go back, since the code
is as easy to write as synchronous code.

Then you have proper support for generics(unlike Java which has type erasure),
LINQ queries and an amazing IDE which is visual studio.

~~~
nicoburns
I think C# is underrated because it was closed source for so long, and working
with a closed source ecosystem is such a pain (and risky!). At least
personally, that made C# a complete non-starter for me before. However, I've
recently started learning it, and it really is nice. It's much more pleasant
to work with than Java.

Hopefully it will see a renaissance when people realise that with ASP.Net Core
they can write code that looks broadly similar to Rails/Laravel/Django code,
and get much better performance more or less for free. There are definitely
some rough edges around the ecosystem though. Entity Framework isn't nearly
nice as Laravel's Eloquent ORM, and it's pretty jarring looking at a promising
library, only to realise that it's a commercial offering (don't get that with
PHP!).

~~~
twodave
If you’re not happy with EF, and don’t mind writing your own SQL, give Dapper
a try. I’ve used a variety of SQL ORMs in C# over the last 12 years, but they
always seem to fall short for me in some way. I like to be in control and also
have nice types, and Dapper is the perfect answer for that.

Yes, you do end up writing some code that a great ORM would just give you for
free, but honestly I haven’t felt pain from doing this as it makes me actually
think about and set in stone what relationships and models I intend to support
in my data layer.

~~~
nicoburns
I find writing raw SQL to be quite annoying for simple CRUD operations. It's
just so easy to make stupid little syntax mistakes when writing SQL. And
things like having to update all your queries if you add a column to your
database are pretty annoying too...

ORM's like Eloquent (PHP) are super nice, because they let you lean on them
completely for simply queries, and then give you layers of opt-outs. For
example, inserting a row is just obj->save(). For slightly tricky selects you
can use the whereRaw method to interpolate raw SQL into just a where clause of
the query, or you can use DB::query() to write a full raw SQL query if you
have some queries that are particularly complex.

I guess I could give Dapper a go though. SQL is... fine.

~~~
wvenable
I think you misunderstand Entity Framework if you think it's _worse_ than
Eloquent. Eloquest is _ok_ and certainly pretty reasonable for PHP. But EF and
Linq are in another ballpark entirely -- it's extremely easy to use and even
allows you to do type-safe queries.

~~~
nicoburns
Perhaps! I'm new to .Net and Entity Framework.

But from what I can see, EF is trying to provide an abstraction layer that
pretends that I am just working with collections of objects, which I don't
like at all because it makes it harder to control which queries actually get
executed and when!

On the other hand, Eloquent provides an abstraction for generating queries,
but this maps pretty closely to SQL, and it otherwise largely stays out of the
way...

The type safety is nice, and of course you don't get that in PHP. But IMO
that's more about the language than the library.

~~~
wvenable
EF will only query exactly what you ask for and will execute the query only at
the point you actually iterate or request an object. For changes, EF will only
hit the database when you call SaveChanges() on the context. It's an
abstraction that _works_ with very few "leaks".

Eloquent also has object collections. Both frameworks have similar methods for
filtering and querying. Eloquent is much more clunky (because PHP) and the
underlying conceptual model is different (ActiveRecord style vs. DataMapper
style). I certainly would use Eloquent for PHP projects but I definitely wish
PHP could do something like EF.

~~~
noir_lord
Doctrine is closer (in terms of actually been a Data Mapper) than Eloquent so
it may be more up your alley.

------
cryptozeus
We just upgraded from .net 4.6 to .net core , without touching any logic
change we are getting 30% performance upgrade. .net core is game changer
within .net community.

~~~
CuriousSkeptic
I think you could expect similar gains going to .net 4.7.2 though most
optimizations done for core has been implemented and enabled for .net to.

------
hugh4life
A few days ago I was checking the former computer language shootout for
another language and saw that C# is beating Java on all the benchmarks. This
surprised me because I always had remembered Java being slightly ahead.

[https://benchmarksgame-
team.pages.debian.net/benchmarksgame/...](https://benchmarksgame-
team.pages.debian.net/benchmarksgame/faster/csharp.html)

Can someone more knowledgeable give me some perspective on how representative
these benchmarks are? At this point would it be wrong to say that in general
the C# and .net environment is more performant than Java? If so, will there be
any changes to Java to bridge any gap?

~~~
nqzero
that benchmark is terrible (see the github for details). for k-nucleotides,
the test that showed the biggest delta (c# vs java), i was able to improve the
java perf by 35%. but the test harness is so poorly done that i didn't bother
running it against the other impls. the reality is that good java developers
just don't care about this sort of thing (which may say something unfortunate
about me) and the benchmark is bad

[https://github.com/nqzero/k-nucleotide](https://github.com/nqzero/k-nucleotide)

~~~
igouy
What a terrible attempt at criticism — `nqzero` says it's terrible so it must
be terrible!

`nqzero` says "the test harness is difficult to configure and use" — but does
not show any example of _what is supposed to be difficult_ about using the
bencher script.

`nqzero` says "the tests are not representative of common programming tasks" —
but does not show any example _common programming tasks_ and does not show
_the tests are not representative_.

`nqzero` says "there's no attempt to account for JIT warmup, and many of the
tasks are too short to ever warm up" — but admits that "it is plausible"
warmup costs are amortised and comparison _will show miniscule difference_.

`nqzero` says "maintainers are opinionated in terms of what code they'll
allow, effectively choosing the winners" — but (again) _does not show any
example_.

`nqzero` says "doesn't appear to allow for jvm options to be included" — but
_seems not to have looked_.

`nqzero` says "the test cpu is from 2007 and is not necessarily representative
of current cpus" — _That at-least is true!_

------
kerng
I always liked C#. It's probably the nicest language to work with. Worked with
golang recently a bit and its like going back to the 90s or 80s. It's just a
little late with all the open sourcing, I just hope besides enterprise devs,
folks would see the value also - most revs I've spoken to that dont like it
havent actually even touched C#.

~~~
highace
I see the same - lots of devs with opinions of M$ and "isn't ASP.NET that
thing with forms and callbacks". Too bad for them!

------
jarym
I'm familiar with both Java and .NET worlds and for a recent product had to
pick one. I ended up picking Kotlin (JVM) only because the team I'm working
with are more proficient in Java but I must admit, C# looked incredibly
tempting technologically.

Java won't go away any time soon but C#/.NET seems to be under better and more
determined leadership.

~~~
maxpert
Have used C# before for almost 5 years. Develeoped for backend and frontend
both! Love the language, love TPL. Kotlin in my opinion brings a better
coroutine implementation. I love they way I can intercept contexts and arrange
them, letting me have go-ish selects, and the structured concurrency. I think
Kotlin might take it a level higer.

------
jchw
Very nice. I had looked into using tasks for TCP servers written in dotnet
core C# recently. I find it mildly annoying that some of the async socket IO
in C# is not easily awaitable, but after working around that I found it fairly
easy. All in all, I see a good future for dotnet core. I can recommend the
Jetbrains Rider IDE to go with it.

~~~
taspeotis
> some of the async socket IO in C# is not easily awaitable

Do any examples come to mind? I thought Microsoft did a pretty thorough job of
adding async support to nearly all of the BCL in .NET 4.5. Not saying there
aren't gaps, I'm just curious. Sockets' non-blocking model is an excellent
candidate for async/await-ifying.

~~~
int_19h
There were plenty of gaps really. Async'ification is still ongoing, but I
don't think we'll ever see it in classic .NET - Core is where it's at these
days.

------
rb808
I moved from C# to Java world - similar but very different. Java has way more
libraries and frameworks which is great, but it almost makes the complexity
worse as there are n different Javas.

The biggest thing is memory management. I never had trouble with GC in dotnet,
Java locks up with full GCs WTF.

------
userbinator
_Obviously C /C++/Rust with handwritten state machines could make this way
smaller, e.g. under 100 bytes. But at some point there are diminishing
returns, and also developer productivity, bugs, and security are big
tradeoffs._

Looking at this another way: you need >20x more memory to achieve the same
level of performance as native code in C#. Suddenly the benchmark doesn't look
that great anymore.

~~~
int_19h
> Looking at this another way: you need >20x more memory to achieve the same
> level of performance as native code in C#.

It's more like, you need 10x more memory with 100x more productivity than
C/C++.

If you don't care about productivity, however, you can actually write C# as
you'd write C, and with a very similar perf profile. You can put everything
into structs to avoid heap allocations, for example. You could use stackalloc,
which basically gives you fixed-size non-bounds-checked stack-allocated
arrays, exactly as in C. You can have pointers that GC knows nothing about,
and you can even do arithmetic on them like in C. You can even have type
punning unions. And then you can put an API on top of all that which makes it
usable with async/await - and write the rest of your code in high-level C#.

------
Thaxll
That thing is not using TCP...

~~~
karl_p
Correct, hard to use TCP for 500K connections for a quick test when there are
only 64K source ports which suffer from TIME_WAIT issues as bonus. It uses
Unix Stream sockets.

~~~
abbeyj
Can you distribute your connections across 127.0.0.1, 127.0.0.2, 127.0.0.3,
etc.? You've got the whole class A reserved as the loopback which should give
you plenty of ports to work with.

------
freecodyx
C# is such an expressive language.

~~~
kuminoter
Which makes it tempting to write a code nobody understands but the author.

------
altmind
Can somebody enlighten me if official microsoft csc is available for linux?
Last time i checked there was mono with some old C# standard and there was
.net core suite... for freebsd only(due to licensing?)

~~~
paavohtl
This must have been some time ago. The .NET runtime / C# compiler you're
thinking of is Rotor, a version of the runtime for educational use released
back in 2006. Mono has followed the official implementation quite closely for
at least the past decade.

The new official C# compiler - Roslyn - was released in 2014. It's open source
and cross-platform. It was followed up same year by .NET Core, which is the
new primary distribution of .NET with support for Windows, Linux, macOS and a
handful of [other] BSD derivatives.

Sources:

[https://github.com/dotnet/roslyn](https://github.com/dotnet/roslyn)
[https://github.com/dotnet/coreclr](https://github.com/dotnet/coreclr)
[https://github.com/dotnet/corefx](https://github.com/dotnet/corefx)

Binaries:

[https://dotnet.microsoft.com/download](https://dotnet.microsoft.com/download)

------
faitswulff
I know nothing of C#, but there are a lot of comparisons to Java in this
thread. Does C# have anything comparable to the JVM? That is, does anything
compile to C# bytecode, if there is such a thing?

~~~
Sammi
Microsoft don't like to admit it but C# and the CLR are their direct response
loosing a lawsuit to Sun taht made them stop developing their own versions of
Java and the JVM.

So Microsoft got the luxury of being able to go back to the drawing board and
try to "do Java right". At least with the knowledge gained from developing
Java in the 90s.

~~~
jacques_chester
Plus they hired a veteran language designer to lead the effort -- Anders
Hejlsberg. Compared to Java they were unapologetic in rapidly iterating the
language and much more aggressive about borrowing ideas from research.

Arguably it came full circle in Java 8, which was a big update to the
language.

------
aliswe
I love C# and .NET so much.

But I dislike some of the stuff being done in .NET Core, for example the
compatibility flags instead of using semver. And integratig GDPR? IN CORE?

VS just feels like a big fat 32-bit legacy application with no support for
long filenames. Its very hard to do improvements for them, that's for sure.
Just look at NuGets package manager UI. Surely there are so many improvements
one could make. (Compare that with the Kaizen feeling you get with each VS
Code update)

I feel MS marketing has too much to say and pushes unnecessary stuff into the
UI. Bring in clippy already!

The tooling for Razor is so extremely buggy, automatic indentation is broken,
try copying pasting imports, changing model type requires reopening of window,
dependent on folder-local web.config to give correct analysis (but still may
compile at runtime)

Also, Im afraid of the frequent updates should something break. (Best to wait
them out a few weeks.)

Then you have the seemingly impossible task of uninstalling it. Better just
reinstall windows itself.

That being said, I guess I feel like they're doing their best on many points.
The code base must really be huge and they are no doubt pouring in lots of
resources improving vs. I was even called once from the US by a womam asking
me for ideas on how they could improve the break-on-exceptions experience
while debugging! I mean who would do that.

And some areas are totally wonderful and unheard of in other platforms, for
example sourceview with full integration with github. I dont think many know
how far ahead .net is on so many levels!

~~~
rhplus
_And integratig GDPR? IN CORE?_

I was puzzled by this comment. From what I can tell, the GDPR stuff is an
optional templating feature in the ASP.NET Core, not a feature of .NET Core.

[https://docs.microsoft.com/en-
us/aspnet/core/security/gdpr?v...](https://docs.microsoft.com/en-
us/aspnet/core/security/gdpr?view=aspnetcore-2.2)

~~~
james_s_tayler
Yeah that's how I understand it too. I thought it was a nice addition and
forward thinking to include it.

------
kuminoter
Anything coming from M$ likely has telemetry (read spyware) sneaked in, so by
the time their packages are audited you would have delivered your software
with different technology. I wouldn't work for companies using unethical
tactics anyway.

