IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New Need a comparison, C#.NET vs Java
Cow-orker is spouting the joy of .NET again. Says one of the advantages is that if you really need to, for performance reasons you can do your own memory management.

Now I think two reasons to use Java are: to not have to handle low-level details like memory management yourself; and platform independence. If I understand correctly, memory management is platform specific. You can't handle it yourself without breaking the indepedence.

He is convinced that if you have an application that is providing a socket pool, and you can't do an "unsafe function" on each connection to free the memory (like he would do it in C#), that every so often Java will start garbage collecting and will become completely unavailable for possibly several minutes.

No, this doesn't sound likely to me. But I don't know enough about the mechanics of memory management to know just how this is wrong.
===

Purveyor of Doc Hope's [link|http://DocHope.com|fresh-baked dog biscuits and pet treats].
[link|http://DocHope.com|http://DocHope.com]
New IBM's JVM has better GC control.
[link|http://www-106.ibm.com/developerworks/ibm/library/i-gctroub/|Here] is an article on what IBM's done to improve garbage collection in their JVM.

The garbage collection implementation is key to the superior performance of the IBM Java Virtual Machine (JVM). While most other JVMs need a lot of tweaking to provide optimal performance, IBM JVMs are designed to work well in most scenarios with their "out of the box" settings. In certain situations, however, garbage collection performance nosedives for no apparent reason. The effects can be an unresponsive server, a frozen screen, or a complete failure, often with cryptic messages such as "Totally out of heap space." Luckily, in almost all such situations, the cause is easy to locate and usually quite easy to correct.

This article shows how to locate potential causes of performance degradation. Since garbage collection is such a vast and complex topic, this article builds on an excellent set of articles already published (see [link|http://www-106.ibm.com/developerworks/ibm/library/i-gctroub/#resources|Resources]).Though most of the suggestions discussed in this article treat your Java program as a black-box, there also are some ideas that you can put in use while designing or coding to avoid potential problems altogether.


It used to be that Sun's JVM GC algorithms were pretty bad. I think they and others have improved them in subsequent JVM implementations. It sounds like he's drunk too much of MS's Koolade.

HTH.

Cheers,
Scott.
New What about platform independence?
Am I correct in thinking that the reason C# makes it so easy to do what he's talking about is that you're probably already on a Windows platform, and all you're doing is calling native Windows methods? If you're willing to abandon portability I'm sure you can call Windows methods directly out of Java.
===

Purveyor of Doc Hope's [link|http://DocHope.com|fresh-baked dog biscuits and pet treats].
[link|http://DocHope.com|http://DocHope.com]
New Warning. C# and .NET are actually quite nice.
"It's a shame it all runs best on Windows, really."

(Not my opinion, but that of drinking buddy whose weapon of choice is J2EE but who has been looking at .NET)


Peter
[link|http://www.ubuntulinux.org|Ubuntu Linux]
[link|http://www.kuro5hin.org|There is no K5 Cabal]
[link|http://guildenstern.dyndns.org|Home]
Use P2P for legitimate purposes!
New Actually, I think dot net is so '90s
it's the framework to end all frameworks, the end result of MS responding to earlier frameworks (VCL, Java, etc) with a super complex and comprehensive framework (admittedly much better than earlier MS crap such as MFC)....coupled with a '90s style inflexible language (C#, C# with BASIC keywords).

It'd be great if everyone still thought C++ was the cat's meow.

But, the programming world has changed with the success of dynamic languages, and programming in .Net is like programming in a straightjacket compared to better options such as Python. I'm hoping IronPython will progress rapidly.
New Corrections
It is true that Java runs GC periodically, and it is true that you cannot do anything while GC runs. But unless you have truly absurd operational parameters, GC will not take minutes to run. In fact it will be barely noticable. An example of how you could get GC to be that slow is if a runaway process caused most of your Java program to go into swap. Then when your Java program tries to run GC you have to wait as the whole thing is brought back out of swap as the GC run tries to access it.

If you're encountering that often then there are several things to fix. First and foremost, track down the runaway programs and fix them. Second, get more RAM. Third (if this is a server environment), get another server and split jobs up so that a single bad process doesn't screw everyone up every time. Fourth, consider running your server with swap disabled or (if your OS has such a notion) swappiness turned down. (That trades problems, it is easier to get out of memory, but memory pressure doesn't slow things down so badly.)

As for memory management, you're mostly wrong about that.

Being precise, it is true that the details of how the system handles swap and requests for memory are platform specific. However those details are hidden behind standard API calls like malloc/free that are very portable. Once you have memory assigned, it is up to you to track what used, which is application-level logic and therefore has every reason to be portable. When people talk about garbage collection algorithms they are inevitably talking about the latter piece, how within your program you track what memory is in use and what memory is not (and therefore can be reused without asking the system for more memory).

Therefore what people mean by garbage collection is very portable, and your basic memory management is likewise trivial to port. The exact behaviour of how that program behaves as you run out of memory will be very platform specific, but the code is portable.

As for his theories, unless he is doing something oddly stupid that leaks memory fairly quickly on each socket, he's smoking crack. It may well be that he saw some behaviour that he thinks his current practice solves, but I'd give very good odds that he misdiagnosed the situation and has developed a superstition based on an item of misunderstood experience.

Cheers,
Ben
I have come to believe that idealism without discipline is a quick road to disaster, while discipline without idealism is pointless. -- Aaron Ward (my brother)
New Haven't studied memory managmenent, don't want to
I haven't studied memory management and I certainly don't want to. It would require months of study and experimentation for only marginal improvements. I have better things to do with my time such as designing an architecture with better load distribution in the first place, clustering, caching at various levels and database tuning.

It's like arriving at a pub and noticing they don't sell Fosters. This affects me, how?
Matthew Greet


But we must kill them. We must incinerate them. Pig after pig, cow after cow, village after village, army after army. And they call me an assassin. What do you call it when the assassins accuse the assassin? They lie. They lie and we must be merciful to those who lie.
- Colonol Kurtz, Apocalypse Now.
New Key differences: One of them sucks
the other sucks more.

They are basically the same language running on roughly the same architecture.

C# has good integration with COM and thus you have easy access to the wide variety of shaky windows code that everyone else relies on when working in real languages to write shrink wrapped code.

Java uses a LCD integration approach to the OS at the VM level and adds a JNI interface that is mostly based on C. Any COM interfacing you do will be more work probably.

Neither JNI nor COM are generally portable, however if you can write the JNI in portable C, then it can be ported easily. COM, like C#, isn't going anywhere. You are irrevocably tied to CrapOS XPee or whatever version is presently victimizing you.

Brief commentary on your cow-worker's comment regarding memory management. He's a 'tard and shouldn't be trusted with anything more advanced than VB.

JNI and unmanaged code are not there for memory management - they are there for access to native code. More to the point, in both JNI and unmanaged code you MUST manage memory, but the VM based objects are managed by the VM. Two worlds which must not collide.

Second, Java should never rely on the GC to release system resources. IOW, its not a bad idea to check for a socket to be closed in finalize, but don't rely on finalize being called. You can run out of socket descriptors long before you run out of memory. So you all close on the java sockets. You should do the same on the C# sockets. Dropping into unmanaged code for something this mundane is the mark of a true idiot. Please whack him over the head with a fresh mackerel 50 times for me.

As to GC. The JVM can be run in either client or server mode (you pass --server on the command line or something). In server mode, GC runs much more often and the passes are much more finely grained such that you never really see any pauses because its all much better interleaved. Client mode seems to defer GC for longer periods and then the GC spikes more noticeably.




"Whenever you find you are on the side of the majority, it is time to pause and reflect"   --Mark Twain

"The significant problems we face cannot be solved at the same level of thinking we were at when we created them."   --Albert Einstein

"This is still a dangerous world. It's a world of madmen and uncertainty and potential mental losses."   --George W. Bush
New Is "unmanaged" what he means when he says "unsafe function"?
Oh, and someone here linked to a blog entry explaining how excessive optimization in a high-level language indicates you should be switching to a lower-level language at that point. And that you don't know what those points are until you've written and benchmarked your app. So choosing a language based on the potential to make low-level optimizations for performance reasons seems like putting the cart before the primordial ooze.

But this is the guy's first gig out of college. You can't tell him anything. Or at least I can't tell him anything. Why, I don't even have a degree or nothin'.
===

Purveyor of Doc Hope's [link|http://DocHope.com|fresh-baked dog biscuits and pet treats].
[link|http://DocHope.com|http://DocHope.com]
New Send him here
Let him argue with us for a bit.

Lots of us have degrees, and a lot more experience than he does.

If he likes to argue, there is a chance that eventually he'll see the light.

Cheers,
Ben
I have come to believe that idealism without discipline is a quick road to disaster, while discipline without idealism is pointless. -- Aaron Ward (my brother)
New Seconded.
I remember heavy discussions in the past with certain opinionated people that involved massage information exchanges. Whilst we may not have changed the mind of the individual in question, a lot of other people learnt quite a few new things.

Wade.

Is it enough to love
Is it enough to breathe
Somebody rip my heart out
And leave me here to bleed
 
Is it enough to die
Somebody save my life
I'd rather be Anything but Ordinary
Please

-- "Anything but Ordinary" by Avril Lavigne.

New Thirded
Why even moi learned (so many moons ago .. maybe at IW?)

what happens when you run your video driver in Ring 0;
not to mention all the odoriferous stuff surrounding that Mephistophelian concept, dll-Hell ..
ie when using crapware, there's a certain satisfiction in finding out Why it's as crappy as you noticed:
there are so many layers of crap-think... behind the parts that merely smell!




I, all unWorthy of this free edjaKayshun
New Your honeymoon's showing.
"Massage information exchanges"?

TMI!


Peter
[link|http://www.ubuntulinux.org|Ubuntu Linux]
[link|http://www.kuro5hin.org|There is no K5 Cabal]
[link|http://guildenstern.dyndns.org|Home]
Use P2P for legitimate purposes!
New :-)
New I read a statistic once ...
I won't try to remember the number, but someone calculated the amount of genetic data transferred in a single, ummm ... protien injection.
===

Purveyor of Doc Hope's [link|http://DocHope.com|fresh-baked dog biscuits and pet treats].
[link|http://DocHope.com|http://DocHope.com]
New That wasn't a deliberate misunderstanding, was it?
I was referring to early discussions with Bryce, actually, back on IWE. Which I'm sure you would have figured out.

Wade.
Save Fintlewoodlewix
New </jokeson>


Peter
[link|http://www.ubuntulinux.org|Ubuntu Linux]
[link|http://www.kuro5hin.org|There is no K5 Cabal]
[link|http://guildenstern.dyndns.org|Home]
Use P2P for legitimate purposes!
New Yes, I know. :-)
Save Fintlewoodlewix
New How could it be anything else?!? Paranoia much, eh...? :-)
New Yes
Code is divided into "managed" (no access to dangerous things like pointers and arbitrary memory) and "unmanaged" (basically C++).

Definitely, we could skule him.



"Whenever you find you are on the side of the majority, it is time to pause and reflect"   --Mark Twain

"The significant problems we face cannot be solved at the same level of thinking we were at when we created them."   --Albert Einstein

"This is still a dangerous world. It's a world of madmen and uncertainty and potential mental losses."   --George W. Bush
New OT-OK Todd (and any body else who has a good answer)...
Exactly (and I mean exactly, using standard English and not some Marketing-speak) what is "managed code"? Not being an MS drone (and having happily escaped the .NET revulsionrevolution), I haven't drunk the Kool-Aid, and haven't therefore added this euphemism to my vocabulary yet. Nonetheless, I do find that I need to know what it means (esp. because somebody I respect used it in the parent to this posting).

So, to paraphrase..."Whachewtalkingbout, Willis?"
jb4
shrub\ufffdbish (Am., from shrub + rubbish, after the derisive name for America's 43 president; 2003) n. 1. a form of nonsensical political doubletalk wherein the speaker attempts to defend the indefensible by lying, obfuscation, or otherwise misstating the facts; GIBBERISH. 2. any of a collection of utterances from America's putative 43rd president. cf. BULLSHIT

New Probably not a good answer...but...
...unmanaged code is capable of accessing any system resource with no type constraints (i.e. you can cast any kind to and kind). Managed code just means you are playing in the sandbox, similar to the JVM. Best correlary in the Java world is JNI, but in the case of .net you can basically write native code that still runs within the .net virtual machine. Certain ILM instructions are only available in unmanaged states (i.e. buffer overrun this machine).
New That's a pretty good answer
IOW, in "managed code" its not possible to do things like manipulate arbitrary memory in the machine - a behavior relied upon by things like some viruses and worms. C# has no pointer construct and so you are playing in "the sandbox" as Chris said. You can't hurt anything from there and your code is subject to user defined security policies.

Unmanaged code is like C/C++. You can do anything to any byte in the machine. No safety rails, no sandbox, no second chances.



"Whenever you find you are on the side of the majority, it is time to pause and reflect"   --Mark Twain

"The significant problems we face cannot be solved at the same level of thinking we were at when we created them."   --Albert Einstein

"This is still a dangerous world. It's a world of madmen and uncertainty and potential mental losses."   --George W. Bush
New Any byte in the machine, or...
...any byte in your process's address space? (I assume that my process cannot touch your process's stuff...)
jb4
shrub\ufffdbish (Am., from shrub + rubbish, after the derisive name for America's 43 president; 2003) n. 1. a form of nonsensical political doubletalk wherein the speaker attempts to defend the indefensible by lying, obfuscation, or otherwise misstating the facts; GIBBERISH. 2. any of a collection of utterances from America's putative 43rd president. cf. BULLSHIT

New As much protection as the Operating System provides...
...which for Windows is to say None At All. Unmanaged code is the umbrella of native code that's not managed within the sandbox. All those VBX or COM or COM+ or DCOM things can be invoked within the unmanaged state.
New Re: Need a comparison, C#.NET vs Java
In addition to the other comments, here's some "authoritative" info (that is, it's from Sun about their own memory management) that dispells the old concerns about the pauses:

[link|http://java.sun.com/products/hotspot/docs/whitepaper/Java_HotSpot_WP_Final_4_30_01.html#pgfId=1082008|http://java.sun.com/...tml#pgfId=1082008]

(note: if I read correctly, this is referring to JDK 1.3, so it's old, which means that things have only gotten better for the garbage collector.)


Incremental "Pauseless" Garbage Collector

The mark-compact collector does not eliminate all user-perceivable pauses. User-perceived garbage collector pauses occur when "old" objects (objects that have "lived" for a while in machine terms) need to be garbage collected, and these pauses are proportional to the amount of live object data that exists. This means that the pauses can become arbitrarily large as more data is manipulated, which is a very undesirable property for server applications, animation, or other soft real-time applications.

The Java HotSpot VM provides an alternative old-space garbage collector to solve this problem. This collector is fully incremental, eliminating user-detectable garbage collection pauses. This incremental collector scales smoothly, providing relatively constant pause times even when extremely large object data sets are being manipulated. This provides excellent behavior for:

* Server applications, especially high-availability applications
* Applications that manipulate very large "live" object data sets
* Applications where all user-noticeable pauses are undesirable, such as games, animation, or other highly interactive applications

The pauseless collector works by using an incremental old space collection scheme referred to academically as the "train" algorithm. This algorithm breaks up old space collection pauses into many tiny pauses (typically less than ten milliseconds) that can be spread out over time so that the program virtually never appears to a user to pause. Since the train algorithm is not a hard real-time algorithm, it cannot guarantee an upper limit on pause times; however, in practice, much larger pauses are extremely rare, and are not caused directly by large data sets.

The pauseless collector also has the highly desirable side-benefit of producing improved memory locality. This happens because the algorithm works by attempting to relocate groups of tightly-coupled objects into regions of adjacent memory, providing excellent paging and cache locality properties for those objects. This can also benefit highly multithreaded applications that operate on distinct sets of object data.


Dan


My Blog: dshellman.blogspot.com
New As long as you want to manage the low level details....
...then I suggest picking a [link|http://elswanko.vm.bytemark.co.uk/~fraggle/stuffage/bf.net/|better language than C#] for such doing such chores on the .Net platform.
New :-)
     Need a comparison, C#.NET vs Java - (drewk) - (27)
         IBM's JVM has better GC control. - (Another Scott) - (1)
             What about platform independence? - (drewk)
         Warning. C# and .NET are actually quite nice. - (pwhysall) - (1)
             Actually, I think dot net is so '90s - (tonytib)
         Corrections - (ben_tilly)
         Haven't studied memory managmenent, don't want to - (warmachine)
         Key differences: One of them sucks - (tuberculosis) - (17)
             Is "unmanaged" what he means when he says "unsafe function"? - (drewk) - (11)
                 Send him here - (ben_tilly) - (9)
                     Seconded. - (static) - (8)
                         Thirded - (Ashton)
                         Your honeymoon's showing. - (pwhysall) - (6)
                             :-) -NT - (Another Scott)
                             I read a statistic once ... - (drewk)
                             That wasn't a deliberate misunderstanding, was it? - (static) - (3)
                                 </jokeson> -NT - (pwhysall) - (1)
                                     Yes, I know. :-) -NT - (static)
                                 How could it be anything else?!? Paranoia much, eh...? :-) -NT - (CRConrad)
                 Yes - (tuberculosis)
             OT-OK Todd (and any body else who has a good answer)... - (jb4) - (4)
                 Probably not a good answer...but... - (ChrisR) - (3)
                     That's a pretty good answer - (tuberculosis) - (2)
                         Any byte in the machine, or... - (jb4) - (1)
                             As much protection as the Operating System provides... - (ChrisR)
         Re: Need a comparison, C#.NET vs Java - (dshellman)
         As long as you want to manage the low level details.... - (ChrisR) - (1)
             :-) -NT - (Another Scott)

This too shall pass.
145 ms