Slashdot Mirror


Java IO Faster Than NIO

rsk writes "Paul Tyma, the man behind Mailinator, has put together an excellent performance analysis comparing old-school synchronous programming (java.io.*) to Java's asynchronous programming (java.nio.*) — showing a consistent 25% performance deficiency with the asynchronous code. As it turns out, old-style blocking I/O with modern threading libraries like Linux NPTL and multi-core machines gives you idle-thread and non-contending thread management for an extremely low cost; less than it takes to switch-and-restore connection state constantly with a selector approach."

270 comments

  1. Proof by Anonymous Coward · · Score: 0

    That one person per coffee cup is the best solution. Or not. It could go either way. :p

  2. And this is news? by Just_Say_Duhhh · · Score: 4, Insightful

    Of course old school techniques are faster. We don't drop old school because we want better performance, we drop it because we're lazy, and want easier ways to get the job done!

    --
    I need trepanation like I need a hole in the head.
    1. Re:And this is news? by bolthole · · Score: 5, Insightful

      naw, old school gets dropped simply because it's "old" (ie: not trendy/buzzword compliant).
      Many times, the "old school" way is EASIER than the newfangled way.

      Example: the 100-200 line perl scripts that can be done in 10 lines of regular oldfashion shell.

    2. Re:And this is news? by slack_justyb · · Score: 2, Interesting

      Mod parent up! There is no better way to sum up this article, other than "Yes, we knew that already, but we don't do it that way anymore because we're all lazy."

    3. Re:And this is news? by HFXPro · · Score: 4, Informative

      Except NIO is usually not as straight forward as java io. It isn't particular hard to use either if you learn to use threads to handle the I/O and pass information through queues.

      --
      Reserved Word.
    4. Re:And this is news? by TommydCat · · Score: 3, Funny

      select() sucked the life out of me in the 90s and I don't think I'll ever recover...

      --
      This comment does not necessarily represent the views and opinions of the author.
    5. Re:And this is news? by ShadowRangerRIT · · Score: 3, Insightful

      Asynchronous I/O is by no means easier. There's a hell of a lot more to keep track of, and a lot more work to do to make asynchronous I/O work correctly; synchronous I/O is much easier to code, and apparently it's faster on Linux to boot.

      --
      $_ = "wftedskaebjgdpjgidbsmnjgcdwatb"; tr/a-z/oh, turtleneck Phrase Jar!/; print
    6. Re:And this is news? by MikeyO · · Score: 1

      Except, in this case, the newer version is also not any easier to use, and the old version isn't going to be dropped.

    7. Re:And this is news? by Anonymous Coward · · Score: 0

      TFA really says the old school techniques WERE the fastest techniques in the old school days, but that the advances in hardware and OS management of threads has "flipped the script" as the youngsters might say.

    8. Re:And this is news? by djKing · · Score: 2, Insightful

      Except NIO is the old school C/C++ way to do it. One thread per socket was the new Java way. So NIO was new to Java, but still old school.

      --
      Free as in "the Truth shall set you..."
    9. Re:And this is news? by cosm · · Score: 4, Insightful

      Of course some old school techniques are faster. We don't drop old school because we want better performance, we drop it because we're lazy, and want easier ways to get the job done!

      Minor addition to your comment, for some may get the wrong impression if it gets modded up the chain.

      That is a bit of a generalization, and not necessarily accurate. I would say that heavily tested, tried and true techniques are faster. Libraries that fall into the aforementioned realm tend to be older, and hence more time for testing and refinement, but being old doesn't necessarily guarantee it will always be faster all of the time, as your comment implies.

      --
      'We are trying to prove ourselves wrong as quickly as possible, because only in that way can we find progress.' RPF
    10. Re:And this is news? by Anonymous Coward · · Score: 0

      Um, No. There is no async. I/O in the standard of either language (and there is no such thing a C/C++).

    11. Re:And this is news? by Anonymous Coward · · Score: 0

      Most likely your X is configured to use /dev/mice, which is the HID device for "all of the inputs from all of the mice plugged into this computer mixed into one"

      The problem is that you'll need to figure out what device the mouse you want to use is, and point X to that device, and hope it doesn't change (ie you never unplug the usb mouse, and it never gets detected first due to a delay etc).

      The other choice is to figure out if your touchpad loads through a module (eg synaptic) and blacklist that module to keep it from loading.

      Or, rewrite the HID layer so that you can instruct it to disable a specific input on demand. Or, if your touchpad uses the USB HID mouse, rewrite the HID mouse driver to blacklist that USB device ID.

      The possibilities are endless!

      (The answer is no.)

    12. Re:And this is news? by jellomizer · · Score: 1, Interesting

      Perl is not New Fangled. I am sorry to say Perl is one of those .COM languages that has sparked peoples interest for a few years but have settled down to niche language. So it is now an Old School Language... Sorry...

      Lines of code doesn't equate to easy. I could write almost any program with one line of code of APL. However there is a steep learning curve to APL, Debugging APL code is near impossible and what is worse is trying to add updates to it. Perl can be coded very Dense as well with heavy use of Regular Expressions... However Regular Expressions come at a cost of readability and upgradability as well.

      --
      If something is so important that you feel the need to post it on the internet... It probably isn't that important.
    13. Re:And this is news? by Just_Say_Duhhh · · Score: 1

      but being old doesn't necessarily guarantee it will always be faster all of the time, as your comment implies.

      Yes, being old does guarantee it will always be faster. Now all you kids get off my lawn!

      --
      I need trepanation like I need a hole in the head.
    14. Re:And this is news? by ShadowRangerRIT · · Score: 5, Insightful

      Example: the 100-200 line perl scripts that can be done in 10 lines of regular oldfashion shell.

      Clearly you're not using Perl the way it was meant to be used. This obsession with coding Perl the way you'd code Java (with classes/objects, libraries to do what shell utilities do, etc.) makes it very verbose. But if you use it the old way (quick and dirty scripts, no compunctions about calling to external shell utilities where they can do the job quicker, not bothering with use strict or use warnings, using the implicit variables shamelessly, etc.), Perl is, almost be definition, just as compact as shell. After all, if shell can do it, so can Perl, you just need to wrap it in backticks (and most of the time, Perl can do it natively with equal or greater compactness). Granted, when you code Perl like that it becomes more fragile and the code is hard to maintain. But then, so was the shell script.

      The problem with a lot of verbose Perl scripts is that the developers were taught to program Perl like C with dynamic typing (as I was initially, before I had to do it for a job and read Learning Perl and Effective Perl Programming cover to cover). I'm not completely insane, so I do code with use strict and warnings enabled, but I don't use the awful OO features, and even with the code overhead from use strict, my Perl scripts are usually equal to or less than 120% the length of an equivalent shell script (and often much shorter). Plus, using Perl means you don't need to learn the intricacies of every one of the dozens of shell utilities, most of your code can transfer to environments without the GNU tools (and heck, it doesn't explode if the machine you run on only offers csh and you wrote in bash), and most of what you're doing runs in a single process, instead of requiring multiple processes, piping text from one to another, constantly reparsing from string form to process usable form.

      --
      $_ = "wftedskaebjgdpjgidbsmnjgcdwatb"; tr/a-z/oh, turtleneck Phrase Jar!/; print
    15. Re:And this is news? by osu-neko · · Score: 3, Funny

      Perl is not New Fangled. I am sorry to say Perl is one of those .COM languages that has sparked peoples interest for a few years but have settled down to niche language. So it is now an Old School Language... Sorry...

      :o

      GET OFF MY LAWN!

      --
      "Convictions are more dangerous enemies of truth than lies."
    16. Re:And this is news? by PiAndWhippedCream · · Score: 1

      I use rmmod psmouse . (a line in /etc/modprobe.d/blacklist) It works fine on my Dell D630, it might work for you.

    17. Re:And this is news? by ShadowRangerRIT · · Score: 5, Informative

      .COM languages? You mean a web language? You do realize Perl was written as a replacement for sed, awk and the shell languages (csh, bash, etc.), to make systems administration easier by providing a single language that used a familiar, C-like syntax and made text parsing trivial. The web was a non-entity when Perl was created. The fact that it was an acceptable language for web development is tied to the initial design goal of parsing text quickly, but that was never the purpose of Perl, and the spread of the language was not solely (and not even primarily) due to its use on the web.

      --
      $_ = "wftedskaebjgdpjgidbsmnjgcdwatb"; tr/a-z/oh, turtleneck Phrase Jar!/; print
    18. Re:And this is news? by binarylarry · · Score: 1

      NIO supports async and is a part of the official class library standard.

      You can't have a 1.5+ certified java implementation without it working.

      --
      Mod me down, my New Earth Global Warmingist friends!
    19. Re:And this is news? by cynyr · · Score: 1

      you forgot "disable the trackpad in the bios. your best bet is to join the rest of us and use /dev/event/foo and configure X to only use the pointer stick. or your mouse.

      --
      All of the above was encrypted with a Quad ROT-13 method. Unauthorized decryption is in violation of the DMCA.
    20. Re:And this is news? by MobileTatsu-NJG · · Score: 1

      We don't drop old school because we want better performance, we drop it because we're lazy...

      Hehe yep. Software engineers are lazy and overworked!

      --

      "I like to lick butts!" by MobileTatsu-NJG (#32700246) (Score:5, Informative)

    21. Re:And this is news? by CODiNE · · Score: 4, Insightful

      In agreement with your post...

      As a recent article showed, traditional algorithms may be less optimal on modern systems with multiple layers of cache and various speed memory systems. New or old it's always important to benchmark and find the right tool for your particular needs.

      --
      Cwm, fjord-bank glyphs vext quiz
    22. Re:And this is news? by avgapon · · Score: 1

      I guess those who moderated this insightful are as clueless as the original poster (if not more). Definitely they haven't done any Java NIO code.

    23. Re:And this is news? by Titoxd · · Score: 2, Funny

      That still makes it a .COM language. As in COMMAND.COM, though...

    24. Re:And this is news? by Sir_Lewk · · Score: 2, Informative

      It's not in the C Standard Library, but there most certainly is async IO for C. See 'aio.h' in POSIX for example.

      --
      "linux is just DOS with a UNIX like syntax" -- Galactic Dominator (944134)
    25. Re:And this is news? by steelfood · · Score: 1

      Short of some algorithmic breakthrough, it does imply that older implementations are necessarily faster.

      The answer is that most of the newer methods are merely bloat, developed not for speed and efficiency, but for ease of development and maintenance.

      In the past, successful developers were all highly skilled. It was a necessary trait for success both because development was difficult, and because there were so few ways to make money developing software. Unsuccessful developers stopped developing, and their code does not persist until today.

      Today, anybody and everybody who knows how to write "Hello World" is considered a developer. Thus, the bar for entry, and the bar for success is much lower. Hence, code written today on a "modern" programming language is necessarily less efficient, because the language itself was written for an overall less capable group of people.

      That is not to say that code developed today cannot be as efficient as code written in the old days, nor is it to say that all of the code written back then is necessarily more efficient as the code written today. But as there hasn't really been any algorithmic breakthroughs in many years for most of the computing science field, the upper limit of the efficiency of the code written today is the same as the upper limit of the efficiency of the code written in the past. And chances are, those upper limits have already been hit.

      --
      "If a nation expects to be ignorant and free in a state of civilization, it expects what never was and never will be."
    26. Re:And this is news? by Monkeedude1212 · · Score: 2, Insightful

      Of course old school techniques are faster

      Ha! Hahaha!

      Nonono, that's not the case. You're thinking of language levels. Low Level programming is very close to the hardware and thus, since you are using the very specific instructions, so you don't lose any efficiency unless you wrote your code illogically. A higher level language abstracts it from the hardware, so your commands have to find the proper opcodes to execute.

      Techniques however, are not languages. I can use the same technique I would in C as I would in Assembly or C# or possibly some other very-high level language.

      The idea they try to convey here is You are trying to efficiently thread for a multicore machine. You can either
      A)Use Java's Asynchronous IO (NIO)
      or
      B) Use regular Java IO, with a modern threading library (like Linux NPTL!)
      to achieve this.

      Turns out - B is faster.

    27. Re:And this is news? by Ossifer · · Score: 4, Funny

      Tape a piece of cardboard over it.

    28. Re:And this is news? by Billly+Gates · · Score: 1

      Ease of use?

      Look at your sig?

      It makes me want to run from Perl like the plague. The new bash shell and command line utilities can do most of perl much easier and there are languages that are strict such as python that are readable by mere regular humans. The powershell and .NET makes it a powerful replacement as well. The fact is you do not need piping text around everywhere and using sed and regex if objects are used instead. I do admit it makes the system administrator more of a .NET programmer than a unix one but Perl is no longer used for CGI scripts for good reason. I had a whole college level book on Perl programming and the first chapter showed there were "3" different ways of printing "hello world" and they all vary on context??

      I know its probably your favorite language and I do not mean to bash it. But Perl is not very useful if a team uses it because no one can read each others code as it can very so widely. It was all the rage as was Java a decade ago. Java seems to be living on in its niche of complex serverlet apps.

    29. Re:And this is news? by Anonymous Coward · · Score: 2, Funny

      With regard to Perl OO, I'm reminded of one of my favorite quotes, I think it's from Advacned Perl Programming. Requires some explanation for those not Perl nerds.

      For those unfamiliar, Perl's idea of "objects" are effectively just an OO framework on top of a procedural model. So you have packages, think C++ namespace. All a Perl object is, is a hash that is "blessed" into the package. You just call bless $hashref,package; and it makes it so you can do neat shit like $hashref->doShit, and then $hashref is just the first parameter. Well, part of this, and because it's just a hash reference...there is no encapsulation or protection...no private, no protected..etc.

      I was concerned about this, and the book I was reading noted someone might be. It's response was "Perl takes the approach that you should stay out of its living room because you're uninvited, not because it's holding a shotgun."

      That's Perl programming in a nutshell :)

    30. Re:And this is news? by kenj0418 · · Score: 1

      Example: the 100-200 line perl scripts

      200 lines of perl ? Isn't that enough to code SkyNet. (While disguising it as simple line noise).

    31. Re:And this is news? by Lunix+Nutcase · · Score: 3, Insightful

      In the past, successful developers were all highly skilled. It was a necessary trait for success both because development was difficult, and because there were so few ways to make money developing software. Unsuccessful developers stopped developing, and their code does not persist until today.

      You must not work with much legacy code. I've dealt with shitty code that is both a couple years old to a many decades old (a mix of C, Fortran, Ada, various assembly, etc). This notion that all old programmers were godlike gurus is mostly myth.

    32. Re:And this is news? by KiloByte · · Score: 2, Informative

      One _thread_ is indeed a new way (for certain values of "new"), but back in the day we used fork() instead of non-blocking IO.

      --
      The creatures outside looked from Alt-Right to Antifa; but already it was impossible to say which was which.
    33. Re:And this is news? by Anonymous Coward · · Score: 0

      Async. is done because of ease or performance. Doing async. operations via polling is more deterministic and much easier to analyze (as a system) than blocking on events (e.g., semaphores and interrupts). That is why it is often preferred in real-time systems.

    34. Re:And this is news? by Anonymous Coward · · Score: 0

      Yet, sed, awk, and /bin/sh (or compatible) are generally easier to use than Perl is. Because I can't think of a unix that doesn't ship with a Bourne compatible shell. (Most of them even have the Bourne Again SHell. Afaik, only HP-UX doesn't include it.)

      In that respect, it fails, miserably. (Though it can do all of those things, it's generally more annoying from an administrator's point of view than just using sed and awk. Though admittedly, some swear by Perl.) Comparatively, I would argue Perl is also harder to read than most shell scripts. (I've seen this many times with the newbie test, they can generally read the shell. Perl, they might be able to, but there's a lower percentage.)

    35. Re:And this is news? by KlomDark · · Score: 1

      Yah, forget those .com apps. These days we're only happy with .net apps. But one of these days we'll finally be freed when the days of .exe code are here!

    36. Re:And this is news? by s2jcpete · · Score: 1

      You haven't used NIO then, it is considerably more complex then using java.io.

    37. Re:And this is news? by Dalcius · · Score: 1

      Clearly you're not using Perl the way it was meant to be used.

      I think Larry might disagree with your assertion that Perl was meant to be used in a specific fashion.

      --
      ~Dalcius
      Rome wasn't burnt in a day.
    38. Re:And this is news? by Locke2005 · · Score: 1

      But if you use it the old way... Perl is, almost by definition, just as compact as shell. And several orders of magnitude less readable!

      --
      I've abandoned my search for truth; now I'm just looking for some useful delusions.
    39. Re:And this is news? by rsk · · Score: 1

      I don't know anyone that would say NIO/Selectors is *easier* than straight blocking IO.

      I also hate replies that begin with "of course"... makes me want to pour coffee on someone's lap.

    40. Re:And this is news? by ArsonSmith · · Score: 1

      Other than he probably meant the last 'c' in the string to be a 'z', the code in his sig is quite simple and little more than a kids decoder ring. How would you do the same thing in your favorite language that would make it so much easier?

      --
      Paying taxes to buy civilization is like paying a hooker to buy love.
    41. Re:And this is news? by sjames · · Score: 1

      Funny that, I find Perl really shines when I use it to extract data and create a report.

    42. Re:And this is news? by Entrope · · Score: 2, Interesting

      The extra stuff to take care of is why asynchronous I/O applications tend to have lower throughput than synchronous I/O if you have good OS threading.

      There have only ever been two good reasons to use application-multiplexed I/O: Your OS sucks at threading (like Windows and Solaris the last time I looked at them), or you have more clients than memory. Languages like C and Java require applications to dedicate multiple kilobytes per thread for the thread's stack -- but usually default to megabytes per thread, so if you have thousands of concurrent clients, you will soak up memory in fairly large quantities.

      Applications like IRC and Jabber can have tens of thousands of clients on a single server (until some jackoff decides to DoS it), so there is strong pressure to minimize per-client memory use.

    43. Re:And this is news? by Anonymous Coward · · Score: 0

      sounds like my missus. every night we bind() together, I select() a position, she accepts() and I start to poll() her. I'm read()ing and write()ing like crazy!
      I quite fancy dup()ing her for 3-way fun, but I'm worried she'll abort() our relationship.

    44. Re:And this is news? by sjames · · Score: 1

      He said there's more than one way, he didn't say all of them were good.

    45. Re:And this is news? by Kjella · · Score: 1

      You must not work with much legacy code. I've dealt with shitty code that is both a couple years old to a many decades old (a mix of C, Fortran, Ada, various assembly, etc). This notion that all old programmers were godlike gurus is mostly myth.

      Also a lot of them were gurus in stuff that's not really relevant anymore like saving two bytes of memory here, a function call here and two processor instructions there - at least on the simple C compiler they used in 1987 - at the cost of code clarity, encapsulation and so on. Almost all the spectacular performance failures I see is not due to issues like that, it's that you've created a spaghetti mess and eventually settle for the only solution you found even though it's probably 100x slower than it should have been.

      --
      Live today, because you never know what tomorrow brings
    46. Re:And this is news? by loom_weaver · · Score: 2, Informative

      Of course there are 3 ways to do this and each has subtle differences.

      Likewise, whether you pass a hash, or a reference to a hash, or you shift single parameters off the stack. It's totally up to you!

      I love using perl for integrating to the shell and other systems plus using its text parsing abilities but man its OO is brutal and I wouldn't use perl in any large projects especially if multiple developers are required.

    47. Re:And this is news? by MichaelSmith · · Score: 1

      I find scripts written by other people to be hard to read and because I don't write perl this includes all perl scripts.

    48. Re:And this is news? by xray84 · · Score: 1

      Perl a) has been around since 1987... I realize that 23 years is young in people years, but, okay, really, new-fangled? b) is one of the more productive and expressive languages around, so I would wager that your 100-200 line Perl script that can be written in 10 lines of shell can probable be written in about 5 lines of Perl. (I program in Perl for a living.)

    49. Re:And this is news? by MichaelSmith · · Score: 1

      Oh for the days of BASIC in ROM when peek and poke were the go.

    50. Re:And this is news? by zach_the_lizard · · Score: 1

      And some of us still fork() our way forward. POSIX can be found in many places, even your phone....

      --
      SSC
    51. Re:And this is news? by zach_the_lizard · · Score: 1

      Those things are still relevant, though not to the same extent. I am careful with space when I write networking code, possibly at the level that someone from 1987 was.

      --
      SSC
    52. Re:And this is news? by turbidostato · · Score: 1

      "Funny that, I find Perl really shines when I use it to extract data and create a report."

      Yeah, it's quite practical.

    53. Re:And this is news? by turbidostato · · Score: 1

      "The answer is that most of the newer methods are merely bloat, developed not for speed and efficiency, but for ease of development and maintenance."

      Economically regulated systems tend to optimize the strongest economic constrain. Since in IT that usually means "programmer time", optimizing "for ease of development and maintenance" *is* optimizing "for speed and efficiency" for all that matter.

    54. Re:And this is news? by LionMage · · Score: 2, Interesting

      Java may not be "sexy" anymore (or "all the rage" as you put it), but it is not exactly a niche language. It still runs in surprisingly many places, like cell phone apps (yes, a lot of us still use regular cell phones, and Android is Java-ish but with some tweaks), and more importantly just about every corporate data center uses Java. That last "niche" is pretty huge, and the only thing that threatens Java in that space is dot-Net, the Java platform clone.

      Java, like it or not, has become the COBOL of the 21st century. It's ubiquitous.

      I agree that Perl makes code hard to maintain (especially in the sense that one developer won't necessarily readily understand another's Perl code, since everyone has his own favorite idiom), but you make a lot of claims that I don't see supported by facts. Perl CGI might be frowned on these days in some circles, but there are plenty of sites that use Perl as a basis -- including this one, Slashdot. So saying Perl is no longer used for CGI scripts is probably false, as there are plenty of folks who clearly think it's "good enough."

      You're trying to make Perl and Java both sound like fads, but the truth is neither language is going away anytime soon, as each is too useful for too large a segment of the developer population.

    55. Re:And this is news? by FoolishOwl · · Score: 3, Funny

      Some people are less afraid of SkyNet than they are of regular expressions.

    56. Re:And this is news? by FoolishOwl · · Score: 1

      Bah. It just lists rubbish. And it's pathologically eclectic.

    57. Re:And this is news? by FoolishOwl · · Score: 1

      In that essay, he's got the clearest explanation of the concepts of "modern" and "postmodern" that I've ever seen -- and I used to be a literature student.

      The Modern period was not misnamed. True, the ordinary word ``modern'' is associated with ``new'' and ``now'', but the historical period we call Modern chose to associate itself with the ``new'' and the ``now'' in such a deep way that we actually see the breakdown of the whole notion of periods. The Modern period is the period that refuses to die. The world is now an odd mix of the Modern and the postmodern. Oddly, it's not just because the Modern refuses to die, but also because the postmodern refuses to kill the Modern. But then, the postmodern refuses to kill anything completely.

    58. Re:And this is news? by LionMage · · Score: 0, Redundant

      Maybe I missed some humor here (aside from the played out "get off my lawn" crap), but retorting to a reply with "Nuh-uh!" doesn't make for effective counter-argument.

      Fully expecting someone to reply to me with "Nuh-uh!" C'mon, you know you want to...

    59. Re:And this is news? by LionMage · · Score: 1

      There haven't been any algorithmic breakthroughs in many years for most of the computer science field? I find that hard to believe. Back in 1993, I was taking a graduate level course in algorithms, and the professor told us about at least one algorithm for multiplying ridiculously large matrices had been developed and published within the prior year (maybe it was 2 years at that time) by a Russian PhD. Granted, this particular algorithm didn't provide a speed benefit over other techniques until you hit matrix sizes of a million by a million, something on that order. But that's not the point.

      You'd also be amazed at what effect seemingly insignificant choices in the implementation of an algorithm can make. The most extreme case I ever saw like that was something like a factor of 2 difference in speed. You might chalk that up to bad coding, but when that code is locked away inside libraries that ship with the language, rank-and-file developers might get stuck with a suboptimal implementation. So it's not just the algorithms themselves that yield new wins, it's careful analysis and improvement of older implementations.

      Getting back to the topic of this article, I want to point out that I actually used NIO in a project in a corporate environment, and it seemed to give us wins in stability, thread utilization, and memory consumption, among other things. For the environment, it was probably the right choice. Had we been dealing with a newer Linux environment, or a less heavily loaded server, I suppose going with the "old" pre-NIO way of doing socket I/O would have been better.

      Had we been on a Solaris system, I'm told the NIO way would have been the best choice hands down, but the company was moving away from Solaris. Still, this raises a valid point -- in the end, you need to tune your code for the environment in which it's running. So if the OS can't do threads well, the whole thread-per-socket approach will stink compared to select-based semantics. I haven't fully read the PDF yet, but it seems like most of this testing was done in Linux. Results for other OSes are not guaranteed to be the same.

    60. Re:And this is news? by Tanktalus · · Score: 1

      I'm not actually aware of a unix that doesn't ship with Perl, either, so I'm not sure of your point.

    61. Re:And this is news? by Jeremi · · Score: 3, Informative

      but usually default to megabytes per thread, so if you have thousands of concurrent clients, you will soak up memory in fairly large quantities.

      There's an important distinction to make here: a thread's stack will reserve (so many) kilobytes/megabytes of address space, but it won't actually use up very much RAM unless/until the thread starts to actually use a lot of stack space (e.g. by doing a lot of recursion).

      On a 32-bit machine, starting too many threads can allocate all of your process's 2-4 gigabytes of address space, which can cause problems even though you have plenty of RAM still free.

      On a 64-bit machine, on the other hand, the amount of available address space is mind-bogglingly huge, so running out of address space isn't a problem you're likely to run into, even if you run a gazillion threads at once.

      --


      I don't care if it's 90,000 hectares. That lake was not my doing.
    62. Re:And this is news? by Cylix · · Score: 1

      If an individual writes code that is difficult to read or has seriously obscure logic issues it is not a language specific problem.

      Yes, you can force a structure within the interpreter, but that doesn't make a good programmer.

      When I actually do write perl I follow a set of best practices and modern techniques. There is a good deal of older cruft and mechanisms in place for implementing certain methods. However, the rule of thumb for me is if it looks strange it's probably wrong.

      I also have a further advantage in that the material I write is also generally peer reviewed. This will generally expose any further issues or poor semantics that I may have introduced.

      I feel the belief that you need a rigidly structured development language is a poor replacement for foresight and ability.

      --
      "You should always go to other people's funerals; otherwise, they won't come to yours." -- Yogi Berra
    63. Re:And this is news? by Anonymous Coward · · Score: 0

      Neither C nor C++ have anything for threads or sockets. C++0x is adding thread features but that isn't even out yet, much less old school. Any discussion on this for C or C++ would have to be very platform specific.

      I have seen a lot of C and C++ code often for many different platforms and I cannot say I have seen a single way to do it. There are some common techniques but they are a collection of ways to do IO, I am sure at least as varied as the different Java libraries.

      I don't really care how Java does it but I would expect they wouldn't always require one thread per socket. This quickly becomes a bad approach on a server application that has more than a few connections.

    64. Re:And this is news? by Anonymous Coward · · Score: 0

      Whoosh!

    65. Re:And this is news? by mhall119 · · Score: 1

      Perl object can be any blessed reference, they don't have to be hashes. You can use a scalar or array variable too. It's just that blessing a hash gives you the added benefit of using the hash keys like instance variables.

      --
      http://www.mhall119.com
    66. Re:And this is news? by icebraining · · Score: 2, Insightful

      Easier is less important than readable. Remember, "Programs must be written for people to read, and only incidentally for machines to execute."
      (sure, that's not always true - other concerns may take priority, like performance - but it's a good practice).

      Now, about the script itself: wtf is $_ ? Poor naming convections.
      wtf is the regex being applied to? Code less than explicit, hard to follow.
      also, wtf is the print printing?

      Sure, in that case it's easy to follow, but with a larger script that you didn't wrote... well, look at this website!

    67. Re:And this is news? by icebraining · · Score: 1, Troll

      But Perl promotes bad practices, by naming variables like $_ and @_, by having code (in the official docs!) like "while ()", etc.

      You have to fight it to keep your code clean, and when you go to read others' code, it's very difficult.

    68. Re:And this is news? by icebraining · · Score: 1

      Python is similar in the "no private or protected methods". As it was said, "We're all consenting adults here."

    69. Re:And this is news? by icebraining · · Score: 0, Offtopic

      Bash still wins: unzip, strip, touch, finger, grep, mount, fsck, more, yes, fsck, fsck, fsck, umount, sleep.

    70. Re:And this is news? by Anonymous Coward · · Score: 0

      udev is your friend...
      www.kernel.org/pub/linux/utils/kernel/hotplug/udev.html

    71. Re:And this is news? by jinx_ · · Score: 1

      i believe that the AC was pointing out that "C" as defined by "the standard" (whether that be ANSI or ISO) is pretty thin in terms in built-ins.

      even old hands can find interesting tidbits once in a while though. wanna fuck with someone? include and use this guy: http://en.wikipedia.org/wiki/Iso646.h

      --
      jinkusu
    72. Re:And this is news? by MechaStreisand · · Score: 1

      FreeBSD doesn't.

      Mind you, that's not because they have something against Perl. It's rather that when Perl was part of the OS, it was too hard to update it independantly of the rest of the system. (I think that back then, new Perl releases were more frequent than now.) So they put it in ports to make that easier. In practice, it winds up on almost every FreeBSD installation due to so many other ports requiring it.

      --
      Disclaimer: IANAL. This post is, however, legal advice, and creates an attorney-client relationship.
    73. Re:And this is news? by ShadowRangerRIT · · Score: 3, Informative

      I don't see how implicit variables are necessarily bad practice. It's a language convention. Programmers write for loops that iterate over variables named 'i' all the time, and it's usually accepted, if not condoned, even if it's just as lacking in descriptiveness as $_ (and $_ has a well defined role, where i is purely by convention). Perl uses $_ as the default loop variable, certain methods process it by default when provided no arguments, etc. If you know Perl well, it's quite natural. Similarly, @_ holds arguments passed to a function (having it be the default storage for return values is deprecated, so you don't see it all that often in other contexts), and shifting off it is standard. Don't assume your lack of familiarity means it's automatically poor style.

      --
      $_ = "wftedskaebjgdpjgidbsmnjgcdwatb"; tr/a-z/oh, turtleneck Phrase Jar!/; print
    74. Re:And this is news? by elFarto+the+2nd · · Score: 1

      Except that NIO is not asynchronous, it's non-blocking, a subtle different. Java 7 is getting proper asynchronous I/O.

    75. Re:And this is news? by Anonymous Coward · · Score: 0

      As far as I understand, Perl's $_ just means the same as "this" in natural language. It saves you from naming the thing that's right before your eyes.

      In Python, that's "_".
      On calculators, it's "Ans".

      I don't find that all that unusual...
      And if you mean that it has a short, always the same, name: that's the point.

    76. Re:And this is news? by roger_pasky · · Score: 2, Informative

      Excuse me, COBOL itself is still the COBOL of the 21st century, as it still makes banking, airlines and quite a lot of brick and mortar industrial companies keep on rolling. Maybe average slashdotters are out of this reality, but it is still alive and kicking. Please don't blame me, I've never programmed a line of COBOL in my whole live.

    77. Re:And this is news? by Anonymous Coward · · Score: 0

      If you're using one thread per client you're doing it wrong.

    78. Re:And this is news? by DrXym · · Score: 1
      Except NIO is usually not as straight forward as java io.

      Depends what you are trying to do. Regular IO is just fine for sequential file parsing, serialization etc. However if you need random access, memory mapped files or something a little more low level then you have to use NIO.

    79. Re:And this is news? by Anonymous Coward · · Score: 0

      Is that because select() just uses one CPU for all the requests?
      Can't you just fork multiple processes, one per CPU, to fix that?

    80. Re:And this is news? by fuzzix · · Score: 1

      Excuse me, COBOL itself is still the COBOL of the 21st century, as it still makes banking, airlines and quite a lot of brick and mortar industrial companies keep on rolling. Maybe average slashdotters are out of this reality, but it is still alive and kicking. Please don't blame me, I've never programmed a line of COBOL in my whole live.

      I have... and I'm not even that old.

      I once worked writing COBOL for VMS and Mainframe systems in various government departments. It's the job that inspired me to go get a degree.

    81. Re:And this is news? by Anonymous Coward · · Score: 0

      Example: the one-line Perl scripts that can be done in 10 lines of regular oldfashion shell.

      There, fixed it for you.

    82. Re:And this is news? by suds · · Score: 1

      I guess you're from old school! :)

    83. Re:And this is news? by dotgain · · Score: 1

      That's not `bash', it's UNIX.

    84. Re:And this is news? by Anonymous Coward · · Score: 0

      Yes, I was point out that calling it the "old-school C/C++ way" is idiotic. Neither language defines or supports such operations. There are external languages out there to to BOTH strategies. Call one "the way" for the languages doesn't make any sense. They don't dictate any particular way, nor has any "one way" been defined as the preferred way. You do what makes sense for your system.

    85. Re:And this is news? by ultranova · · Score: 1

      We don't drop old school because we want better performance, we drop it because we're lazy, and want easier ways to get the job done!

      Um, threads and blocking I/O are far easier than asynchronous NIO. The only reason I've ever heard for anyone to be proposing using the later is it's supposed to be faster.

      --

      Forget magic. Any technology distinguishable from divine power is insufficiently advanced.

    86. Re:And this is news? by gringer · · Score: 2, Insightful

      Now, about the script itself:

      If you're familiar with Perl, these things are obvious. You need to learn Perl basics before you can understand Perl code.

      wtf is $_ ?

      The default variable, or the "default input and pattern matching space". Many functions are implicitly applied to this variable, and return this variable as a result.

      wtf is the regex being applied to?

      If not otherwise specified, regex are applied to the "default input and pattern matching space".

      wtf is the print printing?

      The print statement is printing the "default input and pattern matching space", which in this case is the result from the previous command.

      Most of the confusion that you have mentioned can be overcome by understanding the "default" concept of Perl.

      --
      Ask me about repetitive DNA
    87. Re:And this is news? by JAlexoi · · Score: 1

      New stuff isn't easier. Java NIO just allows for more connections to be handled simultaneously.

    88. Re:And this is news? by JAlexoi · · Score: 1

      There is a minimal amount of RAM a thread will definitely consume(I think it was somewhere about 1MB). And BTW threads don't have their own address spaces, threads share their address space within their process. While processes have their own address spaces.

    89. Re:And this is news? by Anonymous Coward · · Score: 0

      Your capitalization caused me to read that as "Perl is not New England."

    90. Re:And this is news? by funkmotor · · Score: 1

      Absolutely - I've recently used Java 7 and java.nio to write a demon that watched for new files in a directory - using WatchDir it was very simple allowing me to spend my time coding what to do with the files when they appeared.

    91. Re:And this is news? by DuckDodgers · · Score: 1

      Well, for years a central mantra of the Perl community was "There is more than one way to do it." But Perl6 - which admittedly has been under development for ten years and is supposed to have its first major release from the Rakudo project tomorrow - is a pretty major change from Perl 5 and is supposed to simplify or remove a lot of the features that led to unintentionally obfuscated code.

      At this point, I think the baggage associated with the name Perl might be enough to prevent Perl6 from ever becoming a highly popular programming language. But I like a lot of the features. http://perlgeek.de/en/article/5-to-6 I'm just a code-monkey of mediocre skills, but I'm hopeful that the optional strong typing is a really compelling feature for people - you can write strongly typed code that's easier to maintain, test, and refactor for your production applications and you can skip the explicit type signatures for simple scripts you use to manipulate text.

    92. Re:And this is news? by Yogs · · Score: 1

      But Perl promotes bad practices, by naming variables like $_ and @_, ...

      Implicit variables give some of the same convenience in programming as pronouns in natural language, except unlike pronouns, the implicit variables have the same meaning each time. I've never been a fan of Perl syntax, but if you spend any amount of time in Perl at all $_, and @_ should be old friends.

      I think having form of implicit variables in the language is a great convenience feature and the only thing I'd say is that they should have names that let you know what you're dealing with without internalizing a table of (mostly) $<FOO>. But then again, we're talking about Perl here.

    93. Re:And this is news? by DuckDodgers · · Score: 1

      I think you're speaking more specifically from your own experience. I learned Perl first in a Microsoft environment, then moved to Unix, then started to learn awk, sed, and bash. I don't see how Perl is any worse than they are. Look at these two sed scripts:
      sed = filename | sed 'N; s/^/ /; s/ *\(.\{6,\}\)\n/\1 /'
      sed -e :a -e '/\\$/N; s/\\\n//; ta'

      Is that really any better than a complex line of Perl? sed and awk plus bash are better than Perl when you're already competent with sed, awk, and bash and you're new to Perl. Perl is better when you're competent with Perl and new to sed, awk, and bash. The more interesting question is which you would prefer if you were very competent with both sets of tools. I suspect the answer is usually Perl, but then I'm biased.

      Also consider that Perl is more complicated than shell scripts because, of course, it supports a much more rich set of features. In that sense the comparison isn't really fair - Perl syntax would certainly be simpler if it could do far fewer things.

    94. Re:And this is news? by DuckDodgers · · Score: 1

      I don't know if Perl6 will ever become that popular, but its object model does support encapsulation. It also keeps the Perl5 way of blessing objects with a package if you want to do that.

    95. Re:And this is news? by slim · · Score: 2, Insightful

      fork() is still the way forward in many, many situations. Having every server session in its own protected memory space gives me warm fuzzy feelings. One can segfault and the rest will keep on running, and that's just the tip of the security iceberg.

      select() has advantages, described in other posts here, but it has disadvantages too.

    96. Re:And this is news? by DuckDodgers · · Score: 1

      Today, anybody and everybody who knows how to write "Hello World" is considered a developer. Thus, the bar for entry, and the bar for success is much lower. Hence, code written today on a "modern" programming language is necessarily less efficient, because the language itself was written for an overall less capable group of people.

      Sadly, while the barrier to entry might still be that low in other parts of the world, it's getting higher in the US. That's no problem if you're already experienced. But fresh graduates with computer science degrees and a genuine willingness to learn can't find work because it's cheaper to hire a newbie developer from India or China. I have nothing against people from other countries, but it's frustrating to see fresh graduates who should be writing code only finding work as tech support - if they can find work in IT at all.

    97. Re:And this is news? by ShadowRangerRIT · · Score: 1

      wanna fuck with someone? include and use this guy: http://en.wikipedia.org/wiki/Iso646.h

      Thank you for that. Now I can code my C more like Perl (while claiming I'm following standards)! TIMTOWTDI! Bwahahaha! Suffer and die code reviewers! ;-)

      --
      $_ = "wftedskaebjgdpjgidbsmnjgcdwatb"; tr/a-z/oh, turtleneck Phrase Jar!/; print
    98. Re:And this is news? by ShadowRangerRIT · · Score: 1

      And of course, just because they were writing code doesn't mean they were programmers by trade. I've rewritten a decent amount of old F77 Fortran code into C (C99), where the original Fortran was written by mathematicians with enough knowledge to directly translate their equations into code, but not to do it well. This code was running on vector processing machines, and Fortran was designed to take advantage of that in a way the C never was, so the Fortran code should have had the advantage, but they made such elementary algorithmic mistakes that those benefits were wasted.

      For example, in a trebly nested loop (the most touched code in the program), they were counting the bits set in an integer (that was most of the work in the innermost loop actually). They used the naive approach, as opposed to one of the many, many, many portable, efficient means of doing so, and as opposed to using a provided header that defined these sorts of operations as a macro, such that it defaulted to a performant portable technique, but used the most efficient method available for a number of known processors (many of them have an assembly instruction that does what these portable algorithms do, but requires a single instruction, instead of cluttering the line cache with the step by step instructions). The mathematics were beyond my skills at the time, but it was trivial to find and fix all the "mathematically correct, but practically inefficient" sections of the code without needing to understand it all in detail, and the end result in C ran on the same machine in less than 10% of the time, and over half of that savings came simply from swapping in the efficient bit counting macro.

      The end result was not only significantly faster, but was half the length (since macros did a lot of work that had been hand-coded poorly), and easier to read (even before I commented it). Though frankly, anything is easier to read than F77, with its horrible label based loops that make no distinction between the end of the loop and a C-style "continue" statement; it was my first experience with Fortran, and most of the time converting to C was spent figuring out that the fifty "continues" could be converted to C as three loops with a few break and continue statements scattered about (and far less than the original program used; in a nested if statement where each branch triggered a return to the top of the loop, it would be coded individually for each case, rather than putting it in the outer if once, even though it was functionally equivalent).

      In summary, don't let your professional mathematicians implement their own equations.

      --
      $_ = "wftedskaebjgdpjgidbsmnjgcdwatb"; tr/a-z/oh, turtleneck Phrase Jar!/; print
    99. Re:And this is news? by Anonymous Coward · · Score: 0

      The OP was talking about C and C++. Your "certified Java" has nothing to do with it.

    100. Re:And this is news? by ShadowRangerRIT · · Score: 1

      Of course, that same level of care tends to lead to all sorts of annoyances down the road, especially in networking code that is marketed commercially. Microsoft's Remote Desktop has a number of cases where it decided to minimize protocol costs by limiting field width for certain values, only to discover that it became a problem when those assumptions were invalidated. Screen sizes being capped at 4096x2048, working around that to discover that mouse input is not accepted beyond 32767 pixels to the right of the primary monitor, fields that hold IP addresses in string form, and have to be hacked around to make them send IPv4 addresses as strings, but IPv6 addresses as raw binary in order to fit them, etc. And in most cases it doesn't even do that much good, because as they added compression to the protocol, many of the "wasted" bytes were compressed away. For example, in testing, they found that 32 bit color was no more expensive than 24 bit color, and close enough to 16 bit color that you'd be better off tweaking virtually any other display parameter to improve performance before trying to limit color depth. 8 bit color gives you some savings, but it looks like crap, and many modern programs rely on color gradients that require at least 16 bit color to render readably.

      If the protocol had been a little less worried about shaving every byte, it would have been easier to extend. They later managed to fit in a virtual channel protocol that allows arbitrary communication between client and server, so servers that support it can do a lot more without needing to change the underlying protocol, but the overhead of wrapping the extender protocols in that way means it's less efficient now in some scenarios because they insisted on perf boosting compromises in the past.

      --
      $_ = "wftedskaebjgdpjgidbsmnjgcdwatb"; tr/a-z/oh, turtleneck Phrase Jar!/; print
    101. Re:And this is news? by euroq · · Score: 0

      LOL, I can't believe you're arguing with him that Perl is "obvious" and readable. It's not. I understand Perl, but I sure as hell would never say that Perl is easy to read and maintain. It simply isn't. It, by its very nature, tends to make programmers write obfuscated code. You can have obfuscated code in many languages, but Perl practically encourages it.

      --
      Just because the U.S. is a republic does not mean it is not a democracy. Democracy/republic are not mutually exclusive.
    102. Re:And this is news? by euroq · · Score: 0

      If an individual writes code that is difficult to read or has seriously obscure logic issues it is not a language specific problem.

      I call complete bullshit on that statement. Perl encourages code to be difficult to read. I'm not just talking about regexps, either, nor the variable $_. It has semantics that are not as close to natural languages as other programming languages, has obfuscatedly-named commands, and is full of shortcuts (a super-simple example being elsif instead of elseif).

      --
      Just because the U.S. is a republic does not mean it is not a democracy. Democracy/republic are not mutually exclusive.
    103. Re:And this is news? by ciggieposeur · · Score: 1

      Or get a real pipe Input/OutputStream to work.

    104. Re:And this is news? by b4dc0d3r · · Score: 1

      Minor addition to your comment, for some may get the wrong impression if it gets modded up the chain.

      That is a bit of a generalization, and not necessarily accurate. The summary was

      As it turns out, old-style blocking I/O with modern threading libraries like Linux NPTL and multi-core machines gives you idle-thread and non-contending thread management for an extremely low cost; less than it takes to switch-and-restore connection state constantly with a selector approach.

      In that context, as a reply to the summary,

      some old school techniques are faster

      is obviously a generalization, especially with the word "some" in there. You chose to rephrase this as an absolute

      I would say that heavily tested, tried and true techniques are faster.

      Heavily tested techniques don't automatically mean it will be faster, as your comment implies. You may have meant it as a generalization, and not necessarily accurate, but you didn't use "some" as gp post did. Bubble sort is a heavily tested, tried-and-true technique. Lots of solid code is out there and many apps use it, not knowing any better or because it was the first sort they found in their search or book.

      The original was generalizing that if you look at the progression of techniques, we go for ease of use rather than speed. C to C++ to Java to C#, this is typically because the libraries make things easier, not because they run faster. It happens to be quicker to use a standard library sort than implementing your own (unless you have bad MSVS 6 headers, in which case you'll bang your head against the desk trying to figure out why it doesn't work). You can certainly write a faster performing bunch of code, but it's easier to not reinvent the wheel, and faster for the development cycle. So we go for ease of implementation, rather than always choosing the fastest. That's why most websites these days are written in Java or .NET or even php, instead of something compiled like CGI.

      pedant mode off

    105. Re:And this is news? by Anonymous Coward · · Score: 0

      What's your point? There are all sorts of libraries for C. That doesn't make one or the other, the proper or "old-school" way.

    106. Re:And this is news? by Anonymous Coward · · Score: 0

      Well YOU write a parser in assembler then... ;)

    107. Re:And this is news? by lucian1900 · · Score: 1

      There's still the problem that few OSes can even create more than a few thousand threads, let alone schedule them all efficiently. If you have many thousands of connections, sync IO simply dies. Async IO is still slower because it's not being used enough, especially in Java (and for good reason, Java has very bad facilities for callbacks and the like).

    108. Re:And this is news? by lucian1900 · · Score: 1

      Your assumption in equating skill with using bad tools is very wrong. "ease of development and maintenance" is very important regardless of how skilled you are. Writing efficient, but buggy unmaintainable code is not a measure of skill.

  3. Waiting for JDK 7 by Anonymous Coward · · Score: 4, Informative

    JDK7 will bring a new IO API that underneath uses epoll (Linux) or completion port (Windows). High performance servers will be possible in Java too.

    1. Re:Waiting for JDK 7 by binarylarry · · Score: 3, Informative

      Finally, all the worlds enterprise systems can switch to Java... ....oh wait

      --
      Mod me down, my New Earth Global Warmingist friends!
    2. Re:Waiting for JDK 7 by Anonymous Coward · · Score: 0

      FTA:

      To work around not so performant/scalable poll()
      implementation on Linux's we tried using epoll with
      Blackwidow JVM on a 2.6.5 kernel. while epoll improved the
      over scalability, the performance still remained 25% below
      the vanilla thread per connection model
      . With epoll we
      needed lot fewer threads to get to the best performance
      mark that we could get out of NIO.

      TFA also notes that when you are using nio for server programming, you basically will end up coding a threading library because you need to restore the states when switching between clients.

    3. Re:Waiting for JDK 7 by Anonymous Coward · · Score: 2, Informative

      101 Reasons why Java is better than .NET - http://helpdesk-software.ws/it/29-04-2004.htm

      You do more harm than good to Java by comparing it to a 6-8 -year-old version of .NET, since your ignorance gives the impression that we (Java developers) just aren't keeping up with the times. Then again, for as long as you've kept that pageful of crap there in spite of multiple comments like mine, I begin to think that this is your intention.

      How else to explain the fact that in addition to a bunch of invalid arguments, the links to detail for each one bring you to an error page?

    4. Re:Waiting for JDK 7 by binarylarry · · Score: 1

      They're all pretty accurate.

      --
      Mod me down, my New Earth Global Warmingist friends!
    5. Re:Waiting for JDK 7 by Anonymous Coward · · Score: 2, Informative

      JDK7 will bring a new IO API that underneath uses epoll (Linux)

      From TFA:

      To work around not so performant/scalable poll()
      implementation on Linux's we tried using epoll with
      Blackwidow JVM on a 2.6.5 kernel. while epoll improved the
      over scalability, the performance still remained 25% below
      the vanilla thread per connection model. With epoll we
      needed lot fewer threads to get to the best performance
      mark that we could get out of NIO.

    6. Re:Waiting for JDK 7 by teknopurge · · Score: 1

      quiet - you'll make all the python/php/ruby kool-aid drinkers cry....

    7. Re:Waiting for JDK 7 by Anonymous Coward · · Score: 0

      Yeah they are, 1 seems pretty reasonable and 2...oh wait...we only get to the second item before we find one that is blatantly wrong. FAIL

    8. Re:Waiting for JDK 7 by binarylarry · · Score: 1

      Oh right except that Java is open source and .NET isn't.

      Anonymous Coward FAIL.

      --
      Mod me down, my New Earth Global Warmingist friends!
    9. Re:Waiting for JDK 7 by Anonymous Coward · · Score: 0

      Oh right, you're a "java developer" now and not a .NET shill.

    10. Re:Waiting for JDK 7 by keean · · Score: 1

      epoll has already been tried see: "http://www.theserverside.com/discussions/thread.tss?thread_id=26700" The conclusion: "Results shows that the cost of NIO selectors coupled with OS polling mechanism (in this case efficient epoll VS selector/poll) has a significant overhead compared to the cost of context switching 1700 threads on an NPTL Linux kernel."

    11. Re:Waiting for JDK 7 by ultranova · · Score: 1

      JDK7 will bring a new IO API that underneath uses epoll (Linux) or completion port (Windows).

      Doesn't JDK6 already use epoll? I recall having to update glibc a few years back because a new JVM refused to work with an old glibc that didn't implement epoll...

      High performance servers will be possible in Java too.

      But Real Men will still program them in C++, or Assembly if they're wimps.

      --

      Forget magic. Any technology distinguishable from divine power is insufficiently advanced.

    12. Re:Waiting for JDK 7 by mr_da3m0n · · Score: 2, Informative

      Not really. Here:

      • 1. Yes
      • 2. No.
      • 3. In practice they're the same.
      • 4. Worthless. MORE PEOPLE USING IT MEANS BETTER RIGHT?
      • 5. No. It is the /more awesomer/ platform for webservices, but most of the webservices I've seen consumed over the past years were .NET junk that failed SOAP standards and killed my cat.
      • 6. That point is highly, highly debatable. I don't like either.
      • 7. Irrelevant to technical merits.
      • 8. I have seen an equal amount of equally shitty programmers in both languages.
      • 9. Codeplex does exist, and I doubt this is still true today, although it is also irrelevant to technical merits.
      • 10. I don't understand this one.
      • 11. You fail to grasp that you /can/ mix managed and unmanaged hybrid code but you don't /have/ to. By the same logic JNI is such a hybrid and is bad because it exists.
      • 12. That was patently wrong before and is only slightly less wrong now.
      • 13. That would be a concern if .net wasn't already installed everywhere or so.
      • 14. ...

      I have up here. I'm annoyed. And I like Java better than .NET, and I argue this point once in a while. But I don't set up a crappy list with lies and fud to do that.

      And most importantly you failed to mention the one largest selling point to Java: real multi-platform support. And no, Windows 2000, XP, Vista and 7 don't count as "multiple platforms".

    13. Re:Waiting for JDK 7 by joggle · · Score: 1

      According to the report, blocking IO with one thread per connection is faster than even epoll by 25%. From page 18:

      To work around not so performant/scalable poll() implementation on Linux's we tried using epoll with Blackwidow JVM on a 2.6.5 kernel. while epoll improved the over scalability, the performance still remained 25% below the vanilla thread per connection model. With epoll we needed lot fewer threads to get to the best performance mark that we could get out of NIO.

    14. Re:Waiting for JDK 7 by binarylarry · · Score: 1

      So basically you're lying (in the case of #2, .NET isn't open source, Java is) and making excuses for the rest like "nah ahhhh, Imma gone tell on youuuu."

      GG .NET fan boy.

      --
      Mod me down, my New Earth Global Warmingist friends!
    15. Re:Waiting for JDK 7 by mr_da3m0n · · Score: 1

      So basically you're lying (in the case of #2, .NET isn't open source, Java is) and making excuses for the rest like "nah ahhhh, Imma gone tell on youuuu."

      GG .NET fan boy.

      I uh.. what? I'm sorry but you just lost any kind of coherence you previously may have had.

      #2: Not lying. Check your shit before your flail your arms around dismissing my point. Standard library is available under the Microsoft Reference license, i.e., you can step into System.console.writeline() if that is your wish, and that is exactly the point that list argues -- i.e. "you cannot see the source to the .NET standard library without resorting to scary evil illegal means". Which can be refuted easily if you spend five seconds on google. It was never argued that .NET isn't open source.

      You don't even seem to understand that list fully, don't keep yourself updated on the current state of affairs, you just blindly swallow it and spit it back out on demand, and then resort to calling people fanboys as your only argument when someone challenges them.

      I think we're through here. I don't have anything to add.

    16. Re:Waiting for JDK 7 by Anonymous Coward · · Score: 0

      NIO already uses epoll on Linux:
      http://www.docjar.com/html/api/sun/nio/ch/EPollArrayWrapper.java.html

    17. Re:Waiting for JDK 7 by binarylarry · · Score: 1

      You can't tell anyone about what you saw due to all the restricions, so whats the matter arguing the difference. The point is that Java is open and available for review (and modification) and .NET isn't (are you from China or NK or something that you don't get the difference)?

      Of course there isn't anything to add.. you've failed to do that in every post you've made.

      --
      Mod me down, my New Earth Global Warmingist friends!
  4. Old news. by Cyberax · · Score: 4, Informative

    Look at the timestamp of this presentation :) It's a bit of old news.

    It was discussed here: http://www.theserverside.com/news/thread.tss?thread_id=48449

    And it mostly shows that NIO is deficient. I encountered similar problems in my tests. Solved them by using http://mina.apache.org/ .

    1. Re:Old news. by binarylarry · · Score: 3, Informative

      Mina is great although the brains behind the project left and started a new project, Netty.

      I've heard from multiple sources that netty tends to outperform mina although I've been using mina with no problems.

      --
      Mod me down, my New Earth Global Warmingist friends!
    2. Re:Old news. by bill_kress · · Score: 4, Interesting

      I had a problem where the customer wanted to discover a class-b network in a reasonable amount of time.

      Aside from Java's lack of ping causing huge heartaches the limitation was that when using old Java IO it allocated a thread per connection while waiting for a response.

      This limited me to 2-4000 outstanding connection attempts at any time. Since most didn't connect, I needed at least 3 retries on each with progressive back-off times--the threads were absolutely the bottleneck.

      I reduced the time for this discovery process from days (or the machine just locked up) to 15 minutes. With nio I probably could have reduced it significantly more (although at some point packet collisions would have become problematic).

      NIO may not be defective, it just may be solving a problem you haven't conceived of.

    3. Re:Old news. by Alioth · · Score: 1

      Sounds like Java was the wrong tool for the job. There are other languages designed explicitly for massive concurrency which may have worked out better.

    4. Re:Old news. by Anonymous Coward · · Score: 5, Insightful

      Would that be the problem of never having heard about Nmap?

    5. Re:Old news. by udoschuermann · · Score: 1

      NIO may not be defective, it just may be solving a problem you haven't conceived of.

      That's exactly right. NIO was never intended to replace the old school Java I/O, it was intended to solve precisely the type of scalability issues that you encountered, hundreds and hundreds of threads piling up, each sucking up resources that a NIO-based solution would side step elegantly.

      As so often in life, it comes down to understanding the available tools, and knowing when to use which.

      --
      --Udo.
    6. Re:Old news. by Anonymous Coward · · Score: 1, Interesting

      Absolutely.

      First, the paper does says that synchronous NIO is just as fast as (synchronous) IO. So it really is about synchronous vs asynchronous.

      Second, asynchronous is inherently slower than synchronous due to the fact that, in addition to the OS having to figure out what to wake up, the application also has to restore the context in the asynchronous case, but not in the synchronous one, since the state is then more correctly called the stack. The exception is when, due to caching issues or OS limitations *and* the state being so small (as in your case), it is faster to, basically, work around the OS. This obviously is not the general case.

      Last, it's kind of funny to hear asynchronous being presented as the "modern" way, and synchronous/multithreaded as the "old" way, since asynchronous was basically invented to work around the fact that OSes didn't supports threads... Which hasn't been true for a while.

      Cheers.

    7. Re:Old news. by Anonymous Coward · · Score: 0

      Runtime.getRuntime().exec("/bin/ping " + host);

    8. Re:Old news. by RAMMS+EIN · · Score: 1

      ``I had a problem where the customer wanted to discover a class-b network in a reasonable amount of time.
      Aside from Java's lack of ping causing huge heartaches ...''

      So why did you use Java?

      --
      Please correct me if I got my facts wrong.
    9. Re:Old news. by Anonymous Coward · · Score: 0

      Perhaps you should have used the concurrent thread pool and setSOTimeout on the socket to test more than one connection per thread, you would have got much higher throughput and could still poll the timed out connections (it doesn't kill them).

    10. Re:Old news. by bill_kress · · Score: 1

      Yes, but we live in a world where we have certain price/hardware/testing/platform constraints. Java was by far better than any other solution I've seen--There is an established base of developers, there are existing network management platforms. I can't even imagine starting over from scratch on propitiatory hardware and a language we had to learn from scratch, it would have made every project I've ever been on completely fail.

      Not that it's not true in theory, if your theory ignores 100x longer delivery dates (no exaggeration) and 50x "other" cost overruns (Possible exaggeration, maybe not)

       

    11. Re:Old news. by bill_kress · · Score: 1

      I hope you were serious because I'm going to spend a bit of time giving you a serious answer.

      Telcom Network management is a very vertical platform. We have cross-platform development issues, need to interact with many databases and needed a very strong client/server system. We bought a system from Dorado Software that did a lot of the base network management stuff (mapping, discovery, ability to add configuration, etc). We also leveraged a lot of the messaging, client/server and failover capabilities of J2EE.

      This is a pretty damn hard problem space. On top of this large platform that contacted/interacted with/managed many MANY devices, you needed customers to be able to interface to their own specific devices using their devices' own little invented language which is often some off-flavor of SNMP or CMIP--for many devices you just had to programatically telnet/http to the device and interact with it as though you were a user.) We're talking many million dollar devices that take up a room and don't get updated all that often or devices where you have many million deployed... You don't change them, you learn to speak their language instead)

      So as an end customer (say a large telephone company) you might have this Mangement platform from some vendor managing millions of dollars worth of room-sized T1/T2/T3/OC3 switches and terminators. It may also manage end-customer equipment like high-end routers, switches, DSUs, etc. You could even want to go down to the level of managing PCs or cable set-top boxes (imagine how many of those are hooked up to one head-end).

      Now, each of those have software written by their vendor to integrate their hardware into Dorado's platform--either that or the customer has to write that software or contract it out.

      Java was a real boon to this industry--When Java became popular the C stuff (which it all was up until then) pretty much VANISHED. The speed of development, vastly more controllable codebase, easier integration and ability to remove windows from the equation--Windows wasn't considered a professional platform by the Bells for a LONG time and they are slow to integrate changes. They still prefer Unix (not even Linux) for many deployments.

      Java Is pretty much a perfect solution for this space. It let me scan a sparse class B network space in 15 minutes! I challenge you to do significantly better in another language. There is nothing wrong at all with the choice of language, Even with the old IO libraries I was able to singlehandedly replace the ping library with my fast one in a weekend including client/server integration relaying results, scheduling and database updates. I couldn't have done it in a month using C even with a small team, and few dynamic languages would have been quick enough.

      In fact, I was in Network Management for 20+ years and from the time they moved from c to Java, things just took off. Tools started to be reusable, you could buy stuff "off the shelf" that EVERYONE previously had to spend years creating themselves, developers were available and pretty easy to find, the J2EE platform contained a bunch of powerful functionality for free, the list goes on.

    12. Re:Old news. by RAMMS+EIN · · Score: 1

      Hi,

      Thanks for the explanation! I am happy to see that Java has brought a lot of good to your corner of the world! And yes, I was genuinely wondering why you had chosen Java, given that, in your earlier post, you indicated that some of its features and the lack of other features were giving you trouble. Your challenge sounds like fun, by the way. Perhaps I'll give it a shot!

      Cheers,

      Bob

      --
      Please correct me if I got my facts wrong.
  5. NIO? by mhh91 · · Score: 1

    never really used the NIO API,and never saw a reason to,it's not even included in the SCJP exam,which is the basis for all Sun certification

  6. Where's Jobs? by grub · · Score: 1


    Now we just need a Sun spokesperson to have a press conference and show that old-school blocking I/O with modern threading libraries affects all languages, not just Java.

    --
    Trolling is a art,
    1. Re:Where's Jobs? by skids · · Score: 1

      Probably won't happen. My bet on what's going on here is Java OO being so damn heavy it is heavier than the kernel's thread/task struct.

    2. Re:Where's Jobs? by kaffiene · · Score: 1

      Well, your bet is wrong.

  7. NIO != lower latency by yvajj · · Score: 5, Insightful

    I'm not sure where / when NIO got equated to lower latency. The primary benefits of NIO (from my understanding of having designed and deployed both IO and NIO based servers) is that NIO allows you to have better concurrency on a single box i.e. you can service many more calls / transactions on a single machine since you aren't limited by the number of threads you can spawn on that box (and you aren't limited as much by memory, since each thread consumes a fair number of resources on the box).

    For the most part (and from my experimentation), NIO actually has slightly higher latency than standard IO (especially with heavy loaded boxes).

    The question you need to ask yourself is... do you require higher concurrency and fewer boxes (cheaper to run / maintain) at the expense of slightly higher latency (which would work well for most web sites), or are your transactions latency sensitive / real-time, in which case using standard IO would work better (at the cost of requiring more hardware and support).

    1. Re:NIO != lower latency by medv4380 · · Score: 2, Informative

      However, the article and the presentation the article links to point out that IO has better concurrency than NIO. NIO has a Blocking algorithm in it for concurrency and IO has none implemented for Concurrency. The presentation went on to explain what happened because years ago in Java 1.1 and 1.2 it was nasty having to write for concurrency on servers using IO so you'd switch to NIO and be happy. Things have changed because of OS kernel improvements IO is using Non-Blocking algorithms for concurrency without having to be rewritten from scratch. The benchmarks proved it and now NIO has no use if you're using a modern OS with Multicore CPU because IO has better concurrency and throughput then NIO.

    2. Re:NIO != lower latency by pjt33 · · Score: 1

      The presentation went on to explain what happened because years ago in Java 1.1 and 1.2 it was nasty having to write for concurrency on servers using IO so you'd switch to NIO and be happy.

      NIO was new in 1.4, so something's been garbled somewhere.

    3. Re:NIO != lower latency by yvajj · · Score: 1

      However, the article and the presentation the article links to point out that IO has better concurrency than NIO. NIO has a Blocking algorithm in it for concurrency and IO has none implemented for Concurrency. The presentation went on to explain what happened because years ago in Java 1.1 and 1.2 it was nasty having to write for concurrency on servers using IO so you'd switch to NIO and be happy. Things have changed because of OS kernel improvements IO is using Non-Blocking algorithms for concurrency without having to be rewritten from scratch. The benchmarks proved it and now NIO has no use if you're using a modern OS with Multicore CPU because IO has better concurrency and throughput then NIO.

      IO is still "blocking" i.e. requires you to have a thread per connection to wait for incoming data (for your application). This essentially means that you're still limited by the box and the number of connections you can spawn (as well as the nature of the requests).

      A couple years back when we tested this (around 3-4 years back I think), we could at most sustain 6k - 7k connections per box using standard IO (this was not HTTP / web traffic). The issues we ran into were spawing new native threads on the box (ran out of handles on linux) as well as running out of memory.

      With NIO, we were able to sustain around 10k connections per box. Granted you could probably do a lot better now with the latest JVM and newer multi-core boxes.

      Note, these were not pseudo tests... we tested actually "servicing requests" that the servers were designed for. The outcome of the testing may also vary based on what the servers are actually doing (how much memory each request is consuming etc).

    4. Re:NIO != lower latency by GooberToo · · Score: 1

      A couple years back when we tested this (around 3-4 years back I think), we could at most sustain 6k - 7k connections per box using standard IO (this was not HTTP / web traffic). The issues we ran into were spawing new native threads on the box (ran out of handles on linux) as well as running out of memory.

      Anyone who wants scalability NEVER uses a 1:1 thread model. This is why Apache specifically uses a hybrid model to avoid such insanity. A 1:1 model is a recipe for strong contention which is completely contrary to the notion of scalability and actively defeats hardware scalability by adding additional cores/CPUs.

      The fact that you run out of handles on linux means the box was not properly configured.

      The memory issue is easily fixed by either adding more memory or using a sane connection model.

    5. Re:NIO != lower latency by kaffiene · · Score: 2, Insightful

      Exactly!

      It's frustrating to see that 98% of the commentry on this article is clearly from people who don't understand the select vs single thread/poll trade off or who are just out and out ill-informed Java haters. *sigh* This *is* slashdot, I suppose.

    6. Re:NIO != lower latency by yvajj · · Score: 1

      You can use a threadpool (and its the most appropriate way of handling it in many situations), however, you're still bound by the size of the pool. Hence your concurrency and throughput is limited by the size of the pools.

      Our goal at the time was to handle as many connections as possible on a single box due to the cost of having to run a massive cluster (we were look at 500k plus PSU).

    7. Re:NIO != lower latency by Anonymous Coward · · Score: 0

      NIO is about being able to handle large numbers of connections without having dedicated threads. It's a narrow use case, but important for web servers and other components with large numbers of active connections. I'm working on project a the moment that uses NIO. I need to handle 2500 concurrent socket connections with intermittent activity on all sockets. Try that with IO.

    8. Re:NIO != lower latency by GooberToo · · Score: 1

      You can use a threadpool (and its the most appropriate way of handling it in many situations), however, you're still bound by the size of the pool. Hence your concurrency and throughput is limited by the size of the pools.

      Yes and no. That's why, for example, Apache uses thread pools as part of its hybrid strategy. Your pool size should always have some relationship to the hardware on which it runs. So long as you maintain some reasonable relationship, your scalability and level of concurrency largely becomes constrained by the hardware on which you run.

  8. NIO is outdated new version to be released in Fall by Anonymous Coward · · Score: 1, Informative

    Java NIO is actually rather old at this point and is slated for a huge overhaul with NIO.2 which will be released with Java 7 this Fall.

  9. Doesn't scale by Anonymous Coward · · Score: 0

    In the case where you have to manage many thousands of connections the select loop is far more efficent than spawning 1 thread per connection. I can multiplex several hundred connections to the same listen port on one thread and let a fixed thread pool do the computations and let the same (connection) thread serve the result.

    It depends on what you are trying to do. While I did not go over the article completely I fail to see how asynchronous IO can be faster than NIO with buffers and DMA.

  10. is this what I think it is? by blair1q · · Score: 1

    This looks like polling vs. pending, and if it is, pending won that war about 40 years ago.

    1. Re:is this what I think it is? by Alex+Belits · · Score: 1

      No. And you have no idea what are you talking about.

      --
      Contrary to the popular belief, there indeed is no God.
    2. Re:is this what I think it is? by blair1q · · Score: 1

      Maybe it isn't, but I sure as hell do know what I'm talking about.

    3. Re:is this what I think it is? by Anonymous Coward · · Score: 0

      No, you don't. Most real-time systems using polling, because it is more deterministic and much easier to prove you can meet your deadlines. You're just spouting the usually nonsense that people who don't build real-time system say.

    4. Re:is this what I think it is? by blair1q · · Score: 1

      Yes, I do, because I build real-time systems. Extremely complex ones. And they work deterministically because I don't make the mistakes that people who poll in software make because they're polling in software. They're also simpler and use less power and CPU resources than if I was polling.

      If you don't have control of the hardware design, you might be forced to poll in software; otherwise, you're a fool to do it. Most real-time systems are built by fools who rely on appeal to popularity instead of experience in real-time design. Believe me. I get a lot of experience cleaning up after them.

  11. uh...... DUH?! by Michael+Kristopeit · · Score: 5, Insightful

    the entire point of asynchronous is to acknowledge you will be waiting for IO, and try to do something else useful rather than just wait... asynchronous will obviously end up taking more time because of the overhead of managing states and performing the switches, but the tradeoff is something useful was getting done while waiting for IO a little longer instead of doing nothing except wait for the IO to complete. which method is best is completely application specific.

    1. Re:uh...... DUH?! by Anonymous Coward · · Score: 0

      So use the old faster io stuff in a thread while you do other stuff. No need to get all complicated with NIO garbage.

    2. Re:uh...... DUH?! by tepples · · Score: 1
      AC wrote:

      So use the old faster io stuff in a thread

      Provided that you have enough threads available to do "the old faster io stuff". Once you start juggling more than a thousand connections to a server, you run into the kind of limit that bill_kress mentioned.

    3. Re:uh...... DUH?! by Michael+Kristopeit · · Score: 1

      and what if your OS has a thread limit, or otherwise becomes unusable with the number of threads required? it depends on the load of the server, the number of requests, how much IO is required, the average IO waiting time, and the general nature of the application... sometimes it's better to let the OS handle the threads... sometimes it's better for the application to do it... sometimes it's better for the application to be the OS, which on a virtual machine platform like java, is basically the case anyways.

  12. Re:NIO is outdated new version to be released in F by mevets · · Score: 1

    I wonder how much slower nio2 will be...

  13. Suggestion: Skip to page 21 by phantomcircuit · · Score: 2, Insightful

    You'll laugh, hysterically.

    1. Re:Suggestion: Skip to page 21 by medv4380 · · Score: 1

      As funny as it looks it does say not to compare them against each other. They are probably different machines using different hardware, hence the disclaimer on the top. Even though I'd like to believe that Linux 2.6 was 1200% faster then Windows XP I can't bring myself to believe it.

    2. Re:Suggestion: Skip to page 21 by spongman · · Score: 1

      having seen Sun's sources to the win32 part of the JRE, I'm not surprised. not the worst windows code I've ever seen, but close.

    3. Re:Suggestion: Skip to page 21 by ultranova · · Score: 1

      Even though I'd like to believe that Linux 2.6 was 1200% faster then Windows XP I can't bring myself to believe it.

      On the contrary, it's easy to believe; for example, a different disk cache algorithm might easily result in such a difference - in fact, it would be a perfect fit to move the speed from tens of megabytes per second to a gigabyte per second.

      Now, a 100% speedup would be difficult to explain, but this has a simple, natural explanation.

      --

      Forget magic. Any technology distinguishable from divine power is insufficiently advanced.

    4. Re:Suggestion: Skip to page 21 by Arrepiadd · · Score: 1

      What's the part of "*do not compare charts against each other" (right under the main title) that I'm not getting, to understand the joke...

  14. First Post by clintonmonk · · Score: 0

    First post... ..man, I knew I shouldn't have used that Java interface to post on Slashdot.

  15. Should be using Scatter/Gather +IOCP on windows by Saint+Stephen · · Score: 2, Informative

    On Windows, the fastest way to do multithreaded I/O with a producer/consumer queue pattern is IO Completion Ports.

    The fastest way to write a bunch of buffers to disk is WriteFileScatter. The fastest way to read a bunch of data from disk is ReadFileGather.

    SQL Server uses these APIS to scale.

    When I used to work at MS in evangelism, there was a big debate about how Unix does things one way, and Microsoft does it a COMPLETELY different way that you just can't #define away - it's just different. A guy named Michael Parkes said "I cannot go to these clients and say REPENT! and use IO completion ports! They do thread per client, because they have fork()".

    When you listen to the technical explanations, the Microsoft way actually IS better - it's just aht it's totally incompatible with evrything else.

    Learn IOCP and watch your context switches drop.

    1. Re:Should be using Scatter/Gather +IOCP on windows by Alex+Belits · · Score: 1, Troll

      When you listen to the technical explanations, the Microsoft way actually IS better - it's just aht it's totally incompatible with evrything else.

      No. It's only better if the rest of the system is done according to Microsoft ideology -- that is, never try to look at a bigger picture when designing each piece, then go out of your way to make each piece optimal in face of completely un-cooperating environment. Microsoft developers have no idea how Unix-like systems deal with I/O, scheduler and virtual memory all interacting with each other, so after Microsofties introduce massive amount of complexity everywhere, it seems to them that they have an optimal solution for each and every case they tried to optimize. In reality Unix had system that is more optimized and more straightforward for the developer.

      --
      Contrary to the popular belief, there indeed is no God.
    2. Re:Should be using Scatter/Gather +IOCP on windows by Anonymous Coward · · Score: 1, Funny

      The fastest way to write a bunch of buffers to disk is WriteFileScatter. The fastest way to read a bunch of data from disk is ReadFileGather.

      They're actually WriteFileGather and ReadFileScatter. APIs that scattered data around the disk would not be good for performance ;)

    3. Re:Should be using Scatter/Gather +IOCP on windows by KiloByte · · Score: 1

      This is a problem, not a solution. One of bigger problems with win32 development is the multitude of totally incompatible APIs that do the same thing.

      --
      The creatures outside looked from Alt-Right to Antifa; but already it was impossible to say which was which.
    4. Re:Should be using Scatter/Gather +IOCP on windows by Anonymous Coward · · Score: 0

      When you listen to the technical explanations, the Microsoft way actually IS better - it's just aht it's totally incompatible with evrything else.

      Solaris has IO Completion Ports as well.

      *BSD has kqueue.

      Linux has epoll.

      This is not unique to Windows.

    5. Re:Should be using Scatter/Gather +IOCP on windows by PhrostyMcByte · · Score: 2, Interesting

      Actually, they are better for different things. In Linux you get notified when you can perform an I/O, perform a bunch of non-blocking I/O, and then wait for another notification. In Windows you perform an I/O, and it will either complete immediately or notify you when it does. This means async I/O on Linux can use less memory, while on Windows it can give higher throughput.

      Of course, these are merely API advantages -- if the implementation is poor, that won't matter. I'm not aware of any serious tests on this. And even then, Windows lacks an equivalent to Linux's splice(), and its equivalent of sendfile() is crippled on desktop versions to discourage using a desktop as a file server.

    6. Re:Should be using Scatter/Gather +IOCP on windows by thoughtsatthemoment · · Score: 1

      IOCP is very similar to edge triggered epoll of Linux. The main difference is, when the wait function is signaled, the data is already available/sent in/from the buffer. While in epoll, you must call read/write again. It is quite easy to write a common interface to abstract both.

    7. Re:Should be using Scatter/Gather +IOCP on windows by Alex+Belits · · Score: 1

      This means async I/O on Linux can use less memory, while on Windows it can give higher throughput.

      No. It means that you don't know how pending I/O controls the scheduler. On Linux processes are almost never "notified" by asynchronously arriving signals, they are either processing a request, or sleeping while performing a syscall, so they are awakened by a scheduler when whatever they are waiting for (usually data arrived or buffer is available) happened. Scheduler takes into account the number of pending I/O requests and priorities, so processes are awakened in the optimal order -- I/O priority dictates whether it will be for latency or throughput.

      Windows developers followed their typical "Oh!!! It's an event! It looks like a hardware interrupt! I LOVE EVENT HANDLERS! And VMS has the same mechanism! It must be fast!!!" decision-making process instead of trying to actually design a useful data processing mechanism, and predictably ended up with a fine-tuned, convoluted system that works worse than generalized and straightforward one chosen by Unix/BSD/Linux developers.

      --
      Contrary to the popular belief, there indeed is no God.
    8. Re:Should be using Scatter/Gather +IOCP on windows by thoughtsatthemoment · · Score: 1

      you must call read/write again

      I meant the case where the previous call returned with the pending status.

    9. Re:Should be using Scatter/Gather +IOCP on windows by thoughtsatthemoment · · Score: 1

      In Linux you get notified when you can perform an I/O, perform a bunch of non-blocking I/O

      In edge triggered epoll on Linux, a read call can also get immediate result if the data is already there. If not, it returns with a pending code.

    10. Re:Should be using Scatter/Gather +IOCP on windows by Anonymous Coward · · Score: 0

      To be fair, some things in the windows APIs are worth some envy. For instance they let you select() both file handles and synchronization primitives, so that you can simultaneously wait for a file operation and a mutex. I think there was some work put into Linux wrt. to wrapping mutexes in file descriptors, but it was ultimately abandoned, probably because they couldn't get it right.

    11. Re:Should be using Scatter/Gather +IOCP on windows by dr2chase · · Score: 4, Interesting

      I'm afraid I have to disagree. No fan of Microsoft, but I helped build a the-Java-Programming-Language-TM Virtual Machine on Windows, with M:N threads, back before Java 1.4, and IO Completion ports worked well, and we got good performance out of them. We rewrote the network IO to work behind the curtain with threads, with the result that the one-socket-per-thread model actually did the I/O completion port thing, with as many as 32k Java threads running in a grand total of about a dozen Windows threads (stacks were small, stacks grew on demand. Certain things were tricky.).

      The largest wins of doing it this way were:

      1) got to use the underlying OS's preferred way of doing async IO (on another OS, we might do it differently)
      2) lots of threads allowed
      3) because Java "context switches" were extremely lightweight, lots of "expensive" stuff got faster (e.g., lock contention).

      I also accidentally (really -- I had to choose one of two threads to go first, and chose the right one, on a whim) built-in an anti-convoying heuristic for contended locks, that was really useful when code contained a hot lock.

      But, the rest of the system was not especially Microsoft-y; all of us came form a Unix background, and when we were done, we did Unix again. IO Completion ports, at least one Windows, were the best choice (and I tried it 2 or 3 other ways, and they sucked).

    12. Re:Should be using Scatter/Gather +IOCP on windows by Alex+Belits · · Score: 1

      For instance they let you select() both file handles and synchronization primitives, so that you can simultaneously wait for a file operation and a mutex.

      In Unix select()/poll()/... works only on file handles because anything worth waiting on IS a file handle. In Windows there is no unified file handle, so Microsoft developers had to add completely foreign entities to this mechanism. In Unixlike OS the purpose of a mutex is data consistency, not I/O or IPC scheduling.

      I think there was some work put into Linux wrt. to wrapping mutexes in file descriptors, but it was ultimately abandoned, probably because they couldn't get it right.

      It is absolutely unnecessary. Pipes performed this functionality since the very beginning of Unix IPC design, so despite their interface being identical to slower I/O primitives, they are optimized for this use, and on top of that can pass small serialized messages along to the process or thread along with unblocking event.

      --
      Contrary to the popular belief, there indeed is no God.
    13. Re:Should be using Scatter/Gather +IOCP on windows by Alex+Belits · · Score: 1

      We rewrote the network IO to work behind the curtain with threads, with the result that the one-socket-per-thread model actually did the I/O completion port thing, with as many as 32k Java threads running in a grand total of about a dozen Windows threads (stacks were small, stacks grew on demand. Certain things were tricky.).

      Congratulations, you have achieved what Microsoft is still trying to do with .NET -- conceal messy interfaces behind layers of language/runtime that look like less messy interfaces.

      1) got to use the underlying OS's preferred way of doing async IO (on another OS, we might do it differently)

      This is exactly what I am talking about. Windows has deeply flawed infrastructure, so it calls for deeply flawed solutions -- software running on Windows has to use the most convoluted interface because this is the only way to get optimal performance.

      Fortunately, no one in his right mind would optimize high-performance application for Windows because there are other, better systems, with cleaner interfaces. Not that there is a shortage of crazy people and Microsoft fans, but I really don't care about them and neither should anyone else.

      --
      Contrary to the popular belief, there indeed is no God.
    14. Re:Should be using Scatter/Gather +IOCP on windows by Anonymous Coward · · Score: 0

      I don't buy that explanation. Without the mechanism you can either have a multithreaded or a select loop based application. Using pipes for this is rather a hack, there's unnecessary data being copied twice, and take into account that futex locking doesn't even enter the kernel when there's no contention. A futex-fd hybrid could offer the same - select() could return without entering the kernel if the futex was available or wait for it in a system call otherwise.

    15. Re:Should be using Scatter/Gather +IOCP on windows by PhrostyMcByte · · Score: 1

      ...On Linux processes are almost never "notified" by asynchronously arriving signals, they are either processing a request, or sleeping while performing a syscall, so they are awakened by a scheduler when whatever they are waiting for (usually data arrived or buffer is available) happened.

      This sounds a lot like what I said:

      In Linux you get notified when you can perform an I/O, perform a bunch of non-blocking I/O, and then wait for another notification.

      ie. for a single connection they will do as much work as they can, then they need to wait for a notification to find out when they can resume. Was I too tired when I wrote that and not clear enough, or are you simply using this as an excuse to embrace your inner zealot and mock other developers?

    16. Re:Should be using Scatter/Gather +IOCP on windows by Alex+Belits · · Score: 1

      I don't buy that explanation. Without the mechanism you can either have a multithreaded or a select loop based application

      You just use select() in place where would use a mutex otherwise. Mutexes are not supposed to be used that way in the first place.

      Using pipes for this is rather a hack,

      Actually it's one of the most elegant solutions in Unix design. It may look like a hack for a Windows programmer, but so does pretty much everything non-Windows-like.

      there's unnecessary data being copied twice,

      There is the same amount of data copying as with any other messaging interface. If you don't need a message, you can pass one byte, so you only really spend time performing system calls and context switches.

      A futex-fd hybrid could offer the same - select() could return without entering the kernel if the futex was available or wait for it in a system call otherwise.

      First of all, the whole point of this is to remove scheduling logic from userspace and place it into the kernel -- then kernel scheduler can optimize everything based on full information about pending I/O and other forms of waiting instead of blindly preempting processes that may or may not be in the best position to be preempted. Of course, this requires sufficiently lightweight scheduler and syscall interface, something that Windows lacks. You seem to be under impression that Linux or other Unix-like systems achieve their high performance by using some thick userspace scheduler that doesn't perform select()/poll()/... syscall on every call to the library select() (or poll(), etc. in any combination depending on the OS) -- this is not true, modern pthreads implementation is very thin, and days of "green threads" libraries are long gone. Java has thick layers on everything anyway but the OS does not.

      Second, waiting on futex is a syscall anyway, so if you are trying to wait on anything I/O-related, you can just as well wait on a real file descriptor. Futex is only more efficient if it is used purely for synchronization, and therefore there can't be any file descriptors involved.

      Third, if you really care, you can turn futex into a file descriptor and include it into the list of file descriptors you are waiting on.

      --
      Contrary to the popular belief, there indeed is no God.
    17. Re:Should be using Scatter/Gather +IOCP on windows by Saint+Stephen · · Score: 1

      Parkes told me a funny story about how he avoided a lock train wreck - he woke up a thread at random to get the lock.

      His point was that the random threads would be more likely to be local in cache memory than the first waiter, so on average performance would be better. he called it stochastically fair ha ha

      Parkes was a brilliant guy

      Dictated on my iPhone

    18. Re:Should be using Scatter/Gather +IOCP on windows by dr2chase · · Score: 1

      I'm not getting the "deeply flawed" here. IO Completion ports were easy to understand, and pretty fast, and allowed us to post new IOs as they were requested. What's deeply flawed about that, especially compared to "select", which appears to have a linear-in-outstanding-IOs cost built in to its interface?

    19. Re:Should be using Scatter/Gather +IOCP on windows by Anonymous Coward · · Score: 0

      Typically arrogant cocksucker. I bet you're never wrong either.

    20. Re:Should be using Scatter/Gather +IOCP on windows by dr2chase · · Score: 2, Interesting

      The goodness of this strategy assumes some sort of linear-in-delay metric. If there's a deadline, with high penalties for exceeding it (say, if you are serving web pages), you don't want to be stochastically fair, you want to be fair.

      The scheduler I wrote was 100% fair, EXCEPT in the case where a thread exited a critical section that had other threads competing for (i.e., blocked). In that case, the exiting thread would give up its quantum to the head (longest waiter) of the queue, who would do the same, until the quantum expired or the queue of blocked threads was empty, in which case, the last thread through the gate would get the remainder of the quantum (not fair). The result of this is that the lock is left in the unowned state, and threads will get a better chance at blowing right through the critical section in the future.

      You could see how different VMs approached the problem, running things like TP benchmarks, or just a beating-on-a-lock benchmark. We blocked threads in FIFO, another VM did LIFO, another VM did something bimodal and weird. And as far as throughput went, when this sort of badness (a hot lock) occurred, we were far and away the fastest, mostly because of the user-mode context switches, but also because of the no-convoy heuristic that kept locks clean.

    21. Re:Should be using Scatter/Gather +IOCP on windows by Alex+Belits · · Score: 1

      select() "linearizes" operations that are linear under any reasonable scenario anyway, and that buys it complete or nearly complete lack of synchronization primitives in the thread or process that performs it. As long as all long-running processing is delegated somewhere else, and I/O or processing triggered after one call to select() is not likely to be complete before the loop calls select() again, the loop is not a bottleneck, and select() sleeps while OS updates its buffers with I/O. As long as loop includes only minimal, low-latency logic (usually just buffers/requests handling), it can act as a layer between OS scheduler (represented by syscalls) and internal application's request handling (represented by worker threads/processes and buffers).

      In poorly thought out benchmarks, when workers threads are nonexistent and network I/O is instantaneous, select() loop becomes the bottleneck, however this is not a realistic scenario for a server application.

      (obviously, in everything above select() is actually select()/poll()/epoll()/..., as all those interfaces implement the same functionality with different ways of optimizing the access to it -- select() itself is the least scalable of them)

      --
      Contrary to the popular belief, there indeed is no God.
    22. Re:Should be using Scatter/Gather +IOCP on windows by Alex+Belits · · Score: 1

      ie. for a single connection they will do as much work as they can, then they need to wait for a notification to find out when they can resume

      No. It's application's choice if it wants to perform as much work as it can or not every time I/O is available, and how much of this work is done within the same thread as select() -- once triggered, I/O can be delegated to a completely different thread or process. It's not a single connection at a time, either -- select() returns a set of file descriptors available for I/O, and it's kernel's choice how much it will wait before waking up the process and presenting it with multiple file descriptors that became available while the process was sleeping -- priorities and buffers' state can affect this.

      Was I too tired when I wrote that and not clear enough, or are you simply using this as an excuse to embrace your inner zealot and mock other developers?

      Neither -- you merely assume that all uses of select() are exactly the same as the textbook example of a single-threaded, single-process server where everything happens between calls to select(). While some software is indeed written that way (and there are often good reasons for doing so), there are more complex scenarios that make select() or select()-like syscalls useful for high-performance servers.

      --
      Contrary to the popular belief, there indeed is no God.
    23. Re:Should be using Scatter/Gather +IOCP on windows by spongman · · Score: 1

      anything worth waiting on IS a file handle

      not really. the only things in unix that are file handles are handles to open files. however, there are many things that are called file handles, which are, in fact, handles to something completely different.

      really the only difference between windows and unix in this regard is that windows calls them "object handles" instead of "file handles" in recognition of this fact. the idea that you can have a polymorphic API that acts on abstract items is the same.

    24. Re:Should be using Scatter/Gather +IOCP on windows by Animats · · Score: 1

      When you listen to the technical explanations, the Microsoft way actually IS better - it's just that it's totally incompatible with everything else.

      That was the way it was done on mainframes. On IBM and UNIVAC mainframes, I/O could be coded so that I/O completions called back into user code at a high priority, allowing quick setup of the next I/O operation. (Decades ago, I worked on improving the performance of a mainframe tape sorting program, and when the I/O was done right, the tape would run at full speed, without stopping the tape between blocks. I still remember the smooth hiss of the tape drive running in that mode, without all the usual stops and starts.)

      Coding I/O completion routines is much like interrupt-level programming, but inside a user process. It's somewhat harder than UNIX-type 'select' with non-blocking I/O, or multi-thread blocking I/O. But it scales better and provides marginally better performance, provided that you don't choke in the completion routines on contention for locks protecting shared data.

      Windows NT/2000/XP/Vista/7 offer that because they do I/O much like VAX/VMS did it. Dave Cutler was hired from DEC to design NT, and many of the low-level mechanisms are similar.

    25. Re:Should be using Scatter/Gather +IOCP on windows by Anonymous Coward · · Score: 0

      Third, if you really care, you can turn futex into a file descriptor and include it into the list of file descriptors you are waiting on.

      That was precisely my point, you can't.

      Because it was inherently racy, FUTEX_FD has been removed from Linux 2.6.26 onwards. [man futex]

      Anyway, after some thought I concede that using a pipe to notify a select-based thread of new data might be a better idea than a mutex-guarded data structure. But I still wish there was a better way that didn't involve so many trips to the kernel, for communicating with a select() loop thread in the same process. Syscalling and context switching are pretty expensive on Linux too and definitely add latency to your program.

    26. Re:Should be using Scatter/Gather +IOCP on windows by throx · · Score: 1

      That still doesn't explain why you think select() (or epoll) is actually better than IOCP. It more says "select isn't that bad", but says nothing about IOCP itself. I'm curious as to why you believe it is "deeply flawed" and "convoluted" to use completion ports.

      --

      Fear: When you see B8 00 4C CD 21 and know what it means

    27. Re:Should be using Scatter/Gather +IOCP on windows by dr2chase · · Score: 1

      The problem I did not figure out at the time (I think there is a trick idiom, but it was not included in the documentation) was what to do when: 1) I had already fired off a select call with a gazillion socket operations in it, AND 2) Some silly-ass thread has just made a another socket call, which must be performed and added to the set ASAP. My after-the-fact understanding is that I am supposed to include a dummy descriptor in the set, that I control, and to poke on that to force completion, modify the set, and reissue. (This could be very wrong, but, again, none of it was in the documentation.) But, I must also guard against the possibility that some other I/O also completed at the exact same time. What I describe, has to be the wrong way to do it, because each new I/O request incurs linear cost, right? Perhaps the designers of select were not imagining its use in an I/O layer of a VM, but I had no control over the timing of these requests, I was just writing a VM, and I needed to get stuff on/off the wire as fast as possible, up to resource constraints. In the-o-ry, I could accumulate requests "for a little while", but that puts you into "do you feel lucky" land, at least when writing a VM. We tried lots of little experiments, and lots of them had bad corner-case behavior.

    28. Re:Should be using Scatter/Gather +IOCP on windows by swilly · · Score: 1

      the only things in unix that are file handles are handles to open files.

      And directories. And sockets. And pipes. And devices. And probably more that I can't think of at the moment.

      It's a shame this story is too old for anyone to read this.

    29. Re:Should be using Scatter/Gather +IOCP on windows by spongman · · Score: 1

      yeah, that's my point. they're not file descriptors (though that's what they're called); they're descriptors of things that share some API functions with file descriptors.

      windows has exactly the same kind of API abstraction, but instead of calling them 'file descriptors', windows calls them 'object handles'.

      they can refer to:

      • Access tokens
      • Change notifications
      • Communications devices
      • Console inputs
      • Console screen buffers
      • Desktops
      • Events
      • Event logs
      • Files
      • File mappings
      • Heaps
      • Jobs
      • Mailslots
      • Modules
      • Mutexes
      • Pipes
      • Processes
      • Semaphores
      • Sockets
      • Threads
      • Timers
      • Timer queues
      • Timer-queue timers
      • Update resources
      • Window stations

      the APIs are not completely orthogonal, for example to close a socket you call 'closesocket()' instead of 'CloseHandle()'

  16. Thread full of fail by Anonymous Coward · · Score: 0

    NIO was not created to be faster but rather to be scalable. Those are two completely different things. Fail.

  17. Java X faster than Java Y. by Anonymous Coward · · Score: 0

    Yawn ... slow day on Slashdot.

  18. Latency vs throughput by Anonymous Coward · · Score: 0

    AIO gives you latency & scale improvements, not throughput. It's not surprising that synchronous I/O has faster throughput since it saves you a bunch of syscalls. AIO though means that you can handle more concurrent I/O operations even though each individual one may have a lower throughput & you offer more consistently low latency (whereas with synchronous I/O calls may block indefinitely, locking up the UI).

  19. No shit Watson by Alex+Belits · · Score: 2, Insightful

    Ff you have multiple cores that do nothing otherwise (like all benchmarks happen to act), multithreading will use them and asynchronous nonblocking I/O won't, so maximum transfer rate for static data in memory over low-latency network will be always faster for blocking threads.

    In real-life applications if you always have enough work to distribute between cores/processors, your nonblocking I/O process or thread will only depend on the data production and transfer rate, not the raw throughput of the combination of syscalls that it makes. If output buffers are always empty, and input buffers are empty every time a transaction happens, then both data transfer speed is maxed out, and adding more threads that perform I/O simultaneously will only increase overhead. If it is not maxed out, same applies to queued data before/after processing -- that is, if there is processing. So if worker threads/processes do more than copying data, then giving additional cores to them is more useful than throwing them on to be used for I/O.

    --
    Contrary to the popular belief, there indeed is no God.
  20. 2008 by StikyPad · · Score: 1

    This presentation is actually from 2008 (as indicated by every single slide in the PDF -- and thanks for the PDF warning, BTW). Aside from being old, is there any indication that it's still true?

  21. Command.com by 3M by tepples · · Score: 0

    That still makes it a .COM language. As in COMMAND.COM, though...

    What do strips to hang things on the wall have to do with Perl?

    But seriously though, Perl is a .exe language not a .com language because its interpreter is bigger than 65536 bytes. So my best guess is that by ".com language" you meant a language in which programs are stored as source code and parsed when they are run, as opposed to compilation ahead of time.

  22. Who Caaaaarrrrreeeessssss!!!!!! by Anonymous Coward · · Score: 0

    Java people desperately crowing about anything performance related are desperate. It doesn't matter what you do, Java people, Java will never be the fastest thing around because a thing running in a thing will never be faster than a single thing. But that's okay! We all understand how it all works and we can just accept it for what it is. Focus on the important stuff, like eliminating the need to find, download, and install piles of stuff before being able to run a Java program. Make it so that I can download a binary and run it and not know whether the source code was written in C, C++, or Java ... since I really don't care anyway.

  23. Java counterpart to XNA? by tepples · · Score: 0, Troll

    101 Reasons why Java is better than .NET

    All of which are null and void if there's no JVM for your (non-PC) target platform. Which Java edition lets the public program for a game console? .NET does; XNA for Xbox 360 is based on the .NET Compact Framework.

    1. Re:Java counterpart to XNA? by binarylarry · · Score: 1

      So, you're touting .NET's cross platform friendlyness against Java's?

      Really?

      --
      Mod me down, my New Earth Global Warmingist friends!
    2. Re:Java counterpart to XNA? by Sarten-X · · Score: 1

      PropJavelin, for the HYDRA.

      Which XNA version lets the public program for the Wii or Playstation?

      --
      You do not have a moral or legal right to do absolutely anything you want.
    3. Re:Java counterpart to XNA? by smidget2k4 · · Score: 1

      I... just... I don't even know what to say to this other than to echo the other comment.

      Really? That's your argument?

    4. Re:Java counterpart to XNA? by tepples · · Score: 1

      That's your argument?

      Allow me to rephrase: If you're trying to bring an application to a given platform, sometimes the platform forces the language choice. On iPhone, it's Objective-C++; on Windows Phone 7, it's a .NET managed language. I agree that Java is useful on platforms with a JVM, but you may need to reconsider use of Java if your business plan includes expanding to a platform that lacks one.

    5. Re:Java counterpart to XNA? by tepples · · Score: 1

      Which XNA version lets the public program for the Wii or Playstation?

      Nintendo and Sony have made the choice not to let the public develop for their platforms. (Even on PS3, the latest firmware will erase your Other OS.) Microsoft is the only game console maker with a public SDK, and the only way to use Java on its platform is through J#, which Microsoft appears to be phasing out.

    6. Re:Java counterpart to XNA? by tepples · · Score: 1

      So, you're touting .NET's cross platform friendlyness against Java's?

      It doesn't matter how many platforms language X and library Y run on if the set of such platforms doesn't include platform P, and platform P is the only platform that remotely matches the business plan for your application.

    7. Re:Java counterpart to XNA? by SplashMyBandit · · Score: 2, Informative

      FYI: Java will run on platforms that support C. Please see GNU gcj and the Classpath project.

    8. Re:Java counterpart to XNA? by Sarten-X · · Score: 2, Insightful

      So from a different perspective, Microsoft had to kill off Java to get anyone to use XNA, and this is supposed to be evidence of XNA's superiority?

      ...But I digress...

      I don't think you quite got my point. Let's try a few more examples:

      • Which version of XNA can run on a toaster?
      • Which of Boeing's 7x7 series airplanes works best underwater?
      • Which brand of cream cheese is most effective for use as a boat anchor?

      As should be painfully obvious by now, placing arbitrary restrictions on a comparison makes the comparison meaningless. Your original statement was that comparisons are null if the target systems aren't equal. Limiting the discussion to a single case where you know the comparison is flawed makes the comparison useless.

      Instead, let's simply compare where the two technologies can be used. Java can be targeted for many systems. XNA can run on four. For any randomly-selected non-PC target platform, it seems the chance of Java working is significantly higher than XNA (or anything else, for that matter).

      A more equally-weighted comparison is Java vs. .NET. Both are based on publicly-available specifications, and both offer similar functionality. I'd argue that neither is any better than the other in theory, though in practice Java has better support.

      --
      You do not have a moral or legal right to do absolutely anything you want.
    9. Re:Java counterpart to XNA? by tepples · · Score: 1

      A more equally-weighted comparison is Java vs. .NET.

      If your game's back-end (physics and AI) is written in any 100% Pure .NET language, an XNA front-end (input, graphics, and sound) for this game can be created. But the only way to share the back-end between Java front-ends and .NET front-ends appears to be J#, and I don't know how long Microsoft plans to maintain that.

    10. Re:Java counterpart to XNA? by Sarten-X · · Score: 1

      Same facts, different story:

      If your game's back-end (physics and AI) is written in any 100% Pure JVM language, a Java front-end (input, graphics, and sound) for this game can be created. But the only way to share the back-end between Java front-ends and .NET front-ends appears to be J#, or COM or JNI, through one of many supported forms of integration, or use the good old IPC systems the past 40 years have given us.

      It seems .NET is the limiting factor here. Perhaps it'd be better just to get rid of it. This is 2010. There's no good reason to be locked into a language (or platform) anymore. As programmers, we should be thinking about creating the future. We should not be concerned with the ridiculous artificial limitations corporations impose on us. With XNA, Microsoft is giving you a small sandbox, for which they'll charge $99 whenever you try to build something interesting in it. To them, you're not an innovator. You're not a developer. You're a source of income.

      --
      You do not have a moral or legal right to do absolutely anything you want.
    11. Re:Java counterpart to XNA? by tepples · · Score: 1

      or COM or JNI

      .NET has P/Invoke, a rough counterpart to Java's JNI, but in practice, it works only on PC. Non-PC platforms tend to require bytecode to pass the verifier, and they reject all native code not signed by the device maker even if it is compiled for PowerPC or ARM as applicable. Both the Java platform and the .NET framework have this problem. I'll admit I was a bit narrow-minded in claiming that compatibility with a video game console is a notable advantage of .NET over Java.

    12. Re:Java counterpart to XNA? by Anonymous Coward · · Score: 0

      Hmmm. You have it in reverse. C can certainly run on system without memory resource to run Java.

      You can run C in a 8-bit microcontroller with 128 bytes of RAM and 4K of FLASH, but not likely Java.

    13. Re:Java counterpart to XNA? by Sarten-X · · Score: 1

      Technically, you can't run C anywhere. You can run machine instructions that are translated from assembly that was compiled from C, but not C directly.

      Now Brainfuck, on the other hand...

      --
      You do not have a moral or legal right to do absolutely anything you want.
    14. Re:Java counterpart to XNA? by thelexx · · Score: 1

      You don't 'run' C, you compile it.

      And from the gcj page:

      "It can compile Java source code to Java bytecode (class files) or directly to native machine code, and Java bytecode to native machine code."

      The compiled native code would then be dl'd to the device you describe, and executed directly. No VM involved.

      --
      "Gold still represents the ultimate form of payment in the world." - Alan Greenspan, 1999
    15. Re:Java counterpart to XNA? by JAlexoi · · Score: 1

      You do understand that you just blew your own pro-.NET comment, don't you?
      PS: No one ever retracted the Right Too For The Job principle.

    16. Re:Java counterpart to XNA? by tibman · · Score: 1

      That's not a very good argument. I would say there are more platforms that support java than support the .NET Framework. AFAIK, only windows and the xbox have a complete .NET Framework (Windows of all kinds, including winmo). I have used mono and it's very good, but not yet complete.

      Only microsoft can control what is allowed on their devices. When the PS3 could still run linux, it had java. Sony has control of the PS3 platform and removed that ability.

      --
      http://soylentnews.org/~tibman
    17. Re:Java counterpart to XNA? by euroq · · Score: 0

      You don't 'run' C, you compile it.

      You are incorrectly saying that the phrase "C can certainly run on systems" is incorrect. The phrase "run C on a computer" clearly means compile a program written in the C language and execute it.

      --
      Just because the U.S. is a republic does not mean it is not a democracy. Democracy/republic are not mutually exclusive.
    18. Re:Java counterpart to XNA? by tepples · · Score: 1

      You do understand that you just blew your own pro-.NET comment, don't you?

      OK, I admit I was narrow-minded when I emphasized the job of video games. There are jobs where Java is the right tool and jobs where .NET is the right tool. Video games happen to favor .NET over Java at the moment.

  24. This is news? by Locke2005 · · Score: 1

    IIRC, even in Novell NetWare the old blocking I/O calls which prevented the client from doing anything else while it waited for a response from the server were much faster than the new non-blocking I/O...

    --
    I've abandoned my search for truth; now I'm just looking for some useful delusions.
  25. Context-Switching fails at high concurrency by Erasmas · · Score: 1

    I was given the task of handling 10k concurrent connections on a $500 linux box. Standar IO (multi-threaded) quite simply could not cut it - the OS context-switching overhead is prohibitive after a certain number of threads. NIO can handle 10k concurrent connections easily, and keep scaling. At lower-volume, even up to 2000 concurrent connections, regular IO will be fine. But for higher-volume, NIO is a must.

  26. True for JAVA, but not generally true... by grmoc · · Score: 4, Interesting

    This may be true for Java.
    It isn't true for C/C++.

    With C/C++ and NPTL, the many-thread blocking IO style yields slightly lower latency at low IO rates, but offers significant latency variability and sharply decreased thruput at higher IO rates.
    It seems that the linux scheduler is much to blame for this-- the number of times that a thread is scheduled on a different CPU increases dramatically with more threads, and this trashes the caches.
    I've seen order-of-magnitude decreases in performance and order-of-magnitude increases in latency as a result of what appears to be the cache trashing.

    1. Re:True for JAVA, but not generally true... by Ash-Fox · · Score: 1

      Got benchmarks to show this?

      --
      Change is certain; progress is not obligatory.
    2. Re:True for JAVA, but not generally true... by grmoc · · Score: 4, Interesting

      Unfortunately, nothing I can publish without permission.
      I can say that I'm in charge of maintaining the software that terminates all HTTP traffic for Google. Draw your own conclusions.

    3. Re:True for JAVA, but not generally true... by Gverig · · Score: 1

      Sounds very odd (I'm not confident enough in my thoughts to say anything stronger, feel free to explain where I'm wrong).
      Java uses system threads, i.e. it has no internal scheduler. NPTL or others are just an interface into the threading/scheduler so are fairly thin. Thus trends for performance of IO and multiple threads should be consistent between Java & C++. Unless people that implemented threading/IO for JVM implemented it a little differently (better?) that people that implemented your benchmark ;)

    4. Re:True for JAVA, but not generally true... by MassacrE · · Score: 1
      Your assumption may be that the java code to handle asynchronous IO is optimal. However, there may be a big performance hit not from the underlying system, but from the particular JVM’s implementation of asynchronous I/O.

      I know in particular that the NIO system on windows used to use evented sockets rather than IOCP, which among other things meant that IO events were shoved into the windows message pump, and only 32/64 sockets could be handled at one time.

    5. Re:True for JAVA, but not generally true... by Warll · · Score: 2, Funny

      I can say that I'm in charge of maintaining the software that terminates all HTTP traffic for Google. Draw your own conclusions.

      You're head of R&D for a supervillain's start-up attempting to kill the internet?

    6. Re:True for JAVA, but not generally true... by br0k_sams0n · · Score: 1

      This may be true for Java. It isn't true for C/C++.

      With C/C++ and NPTL, the many-thread blocking IO style yields slightly lower latency at low IO rates, but offers significant latency variability and sharply decreased thruput at higher IO rates. It seems that the linux scheduler is much to blame for this-- the number of times that a thread is scheduled on a different CPU increases dramatically with more threads, and this trashes the caches. I've seen order-of-magnitude decreases in performance and order-of-magnitude increases in latency as a result of what appears to be the cache trashing.

      I've seen similar arguments against using hyper-threading with Java. Curious, have you tried limiting the number of threads to prevent the thrashing or a pbind equivalent to keep a thread closer to a cache pipeline?

    7. Re:True for JAVA, but not generally true... by Anonymous Coward · · Score: 0

      My own conclusion is that HTTP over SCSI will be overcome by HTTP over SAS. It needs no termination, dude!

    8. Re:True for JAVA, but not generally true... by Just+Some+Guy · · Score: 1

      I can say that I'm in charge of maintaining the software that terminates all HTTP traffic for Google.

      Nuclear bomb firmware? EMP device simulations? /dev/null? IE 6? Inquiring minds want to know!

      --
      Dewey, what part of this looks like authorities should be involved?
    9. Re:True for JAVA, but not generally true... by Gverig · · Score: 1

      Not really. My assumption is that the same issues grmoc described plague JVM implementation just as well.
      Everything else from this reply to the original article itself... a) I don't know who's those "everybody" that believes that on single socket async is faster than blocking. IMO it's a pretty dumb idea and blocking is as fast as it gets for throughput. People go async not because they want better throughput but because they want to be able to use the cycles on the same thread.
      b) rest is about "what's implemented worse, thread switching or selectors" and that's heavily OS dependent and changes all the time but it's also pretty well known that selectors are crippled with any significant number of sockets. epol works much better AFAIK but on the question of epol vs. thread number- I don't know.

      Ultimately, I believe that neither original post or this reply make any sense and you take a number of factors into account (how you work with data, can you even do multiple threads efficiently, etc.) and not optimize early.

      PS on async, just don't use selectors, period.

    10. Re:True for JAVA, but not generally true... by grmoc · · Score: 1

      I love slashdot!! :)

    11. Re:True for JAVA, but not generally true... by Warll · · Score: 1

      I do too, it's not everyday you get to interact with people capable of killing the internet, and then make jokes out of their comments.

  27. The ideal method by Zan+Lynx · · Score: 1

    The best way to write IO is to use one thread or process per CPU core and in that thread use non-blocking IO. I thought everyone knew this.

  28. Re:NIO is outdated new version to be released in F by mwolfe38 · · Score: 1

    it won't matter, they'll rename nio2 back to nio after realizing that nobody can figure out the java numbering system.

  29. Right, lots of concurrent I/O... by Anonymous Coward · · Score: 1, Insightful

    What really pains me is when people decide to do the "easy" threaded I/O and then evolve strange monstrosities like thread pools to try to deal with the scaling problems. Allocating N*k worker threads to N processors and then doing select-style polling in each of them is just so ugly. Either the OS and language runtime should provide high performance async I/O or unlimited threading via smarter compilers and schedulers (or both). Having every application evolve from "trivial but slow" (simplistic async I/O) or "trivial but fragile" (simplistic threaded I/O) into "very complex but usually fast and scalable" (weird hybrids with thread pooling and application level work dispatchers) is just a terrible waste of software engineering resources.

  30. The Article isn't fair by z-j-y · · Score: 1

    shut up and mod me up.

    I've done similar benchmarking. On average, Java socket IO takes 3000 cpu cycles to handle a packet, including kernel time. That isn't bad for TCP which is a complex protocol.

    Java NIO implementation easily adds another 1000 cycles on top of that. It tries to provide too much abstraction and it does excessive locking.

    Therefore, Java NIO is about 25% slower, it looks like, in a naive saturation test.

    But it's meaningless. 1000 cpu cycle is nothing in a java program. Let's do the simplest non-trivial thing with the data, say, xor each bytes. That's about 2 cycles per byte, and 2000-3000 per packet. That's another 50% slowdown. A real application needs to do much much more than that, and the overhead of Java NIO becomes negligible.

    NIO is better if there are a lot of connections blocked on read/write. But this is odd if you really think about it! Why couldn't thread impl achieve the same thing? As of today, the only reason is that thread stack size is fixed and quite large. Java's default stack size is 256K. A few thousands of threads will consume all the memory on board. If you maintain connection state yourself, it's far smaller than that, and it pays to not create one thread for every connection.

    1. Re:The Article isn't fair by kramulous · · Score: 1

      I'm not arguing with anything you state because, frankly, I don't know better. I don't do java much any more.
      One thing that did grab me with your post was

      1000 cpu cycle is nothing in a java program.

      How many programmers require that mindset before, as you stack layer upon layer upon layer, it all becomes slow as buggery? Maybe that is exactly the reason why I don't look to java any more?

      --
      .
  31. Common sense... by broknstrngz · · Score: 1

    You use threads when your app is CPU-bound and async I/O (it's actually sync, it's just multiplexed, but the name stuck) when it's I/O bound. Using threaded/synchronous models works better when you have a small number of connections, because the OS scheduler can cope with them. Going to 10k connections over the same model is downright stupid. Your software would spend more time switching contexts than performing useful I/O. Hybrid models, with per-thread I/O loops, are a good approach. IIRC, Mina does the same thing, moving connection objects from one thread to another when their state changes, while doing async I/O in each thread. I'm not entirely sure on this, I'm not a Java guy, but I remember reading this in a paper at some point.

  32. If you know what you're doing, OS doesn't matter by Anonymous Coward · · Score: 0

    If you know how to code high-bandwidth, low-latency IO, the operating system doesn't matter, because you'll be hardware limited.

    And believe it or not, you can do a passable job of that with Java.

    But you sure as shit CAN'T with C++ IO streams. There's nobody worse at coding high-speed IO than some noob who can't get past his >> and <<.

  33. gcj by tepples · · Score: 1

    Java will run on platforms that support C.

    XNA Game Studio does not support C or Standard C++. It supports a largely incompatible C++ dialect called "C++/CLI with /clr:safe".

    Please see GNU gcj and the Classpath project.

    Does gcj compile Java into C or directly into object code? The iPhone developer program requires that Xcode and only Xcode compile your program's source code, which must be written in Objective-C (of which C is a subset) or Objective-C++ (of which Standard C++ is a subset).

    1. Re:gcj by Anonymous Coward · · Score: 0

      The iPhone developer program requires that Xcode and only Xcode compile your program's source code, which must be written in Objective-C (of which C is a subset) or Objective-C++ (of which Standard C++ is a subset).

      Are you sure about that? The actual developer's license terms say that it must be in Objective-C, C, or C++. A number of high-budget commercial iPhone apps have been written and compiled in c++ using the AirplaySDK, which doesn't use Xcode and doesn't even have to run on a mac.

    2. Re:gcj by tepples · · Score: 1

      The actual developer's license terms say that it must be in Objective-C, C, or C++.

      Which, for purposes of the article, still excludes Java.

  34. Speed isn't the point... by poor_boi · · Score: 1

    I don't think NIO ever claimed to be faster than old IO. Its primary selling point is (and always has been, IMO), its ability to handle tens of thousands of connections on a single thread. With old IO, ten thousand connections would require ten thousand threads. I don't care how good your context switcher is -- that is a high price to pay, especially if the machine has other high-thread-count processes running as well.

  35. Horrible conclusion, here's why. by Big_Mamma · · Score: 1

    So when you're pushing data as fast as you can through a socket, the old read(byte[]) or write(byte[]) are faster? Wow, no kidding.

    You do NOT use java.nio (like Jetty's SelectChannelConnector) for maximum throughput. You use it to handle persistent connections, like all those long polling requests via AJAX which return on an event or timeout after a minute. This article is like recommending Apache with its hard limits on how many requests it can serve concurrently over newer, asynchronous servers like Nginx for static media servers with keep alive enabled.

    The slides even mentions the C10K problem, but what it doesn't do is mention when to use either technology - async IO for concurrency and endless scaling, and synchronous IO for pushing a 10G Ethernet link to the limits. No wait, the nio setup can do that too, 700MB/s or 5.6Gbit/sec per core on 2008 hardware should be enough to max out anything you can buy now. It's great that synchronous IO can hit 1GB/s, a whopping 30% faster, but useful? I'd say no.

    For most users, you don't use either API. Lets be honest here, writing highly concurrent software is hard, why reinvent the wheel when you can get off the shelve software that can do it better? You use Jetty and choose between the SelectChannelConnector or SocketConnector, or choose between Apache or Lighttpd/Nginx depending on the traffic pattern. What you do write is the bit that accepts a whole HTTP request and returns a HTTP response, everything before and after is magic.

    Unless you're a file server, each 50k sized HTTP response will require enough work to make sure you run out of CPU or Disk IO long before you hit even the 100Mb/s ceiling in most rack switches. Even if your app is fast, 16 cores x 100ms per request x 50K is only 62 Mbits. Not 5600.

    But if you need to scale in concurrent client count, there's no way around async IO. The latest name to watch is Netty. In Plurk Comet: Handling 100,000+ Concurrent Connections with Netty, it scales up to 100000 concurrent connections on a quad core server with 20% CPU load.

    Just stop worrying about sockets already, and start worrying about your SQL server suffering a meltdown. Even if you get manage to grow into the Facebook, it's not like using synchronous IO will save you from deploying 30000 servers, it's the application code that's slow. Zero copy, one copy, "string concatenation style twenty copies response building" socket writes don't matter at all, memcpy is cheap compared to a few lines of interpreted code, servers are cheap compared to developers, and never mind the cost of the programming gods giving these presentations.

  36. Async is newschool? by Anonymous Coward · · Score: 0

    Async I/O predates Java and pthreads by decades.

    On all sane programming environments Async IO is faster for non CPU bound applications as context switches are minimized.

  37. Any news on this since 2008? by dkoulomzin · · Score: 1

    The slides are dated 2008. Was there any follow up? Were these experiments repeated and/or confirmed anywhere else?

    --
    Thou shalt not begin a subject line or post with the word "Umm".
  38. It's not supposed to be faster ... by dave87656 · · Score: 2, Insightful

    My understanding is that it is not supposed to be faster. It is non-blocking and asynchronous which serves a different need.

    1. Re:It's not supposed to be faster ... by mihvoi · · Score: 1

      For me Java NIO (SocketChannel/select/read) worked a lot better then the multi-threaded/blocking version (Socket/read). I had to simulate 5000 TCP clients reading at 128kbps (radio streams), on Linux 2.6 64bits with 4GB RAM, CPU DualCore (Java 1.6). With the multi-threaded version is was a bit easier to code, but it consumed 2*100% CPU before reaching the target. The context switches between threads consumed a lot of CPU. Even before reaching the CPU limit, the Thread.sleep() between reads started to have big delays (>1second), probably because of the scheduler that had to schedule 5000 active threads. With the single-threader, NIO version it reached the target consuming about 20% of one CPU. I had to tweak a bit the reads for this. The problem was that reading in a close loop, there were many short reads, producing many switches between user/kernel space, consuming too much CPU. Putting a small sleep (50-100ms) between each select() resulted in bigger and fewer reads, in the same time consuming all the received data in a single loop.

  39. behind the times by Anonymous Coward · · Score: 0

    Weird, Paul's document has not changed since I last read it 2 years ago, but its still news?

  40. Old news by jevring · · Score: 1

    Actually, Paul published this on his blog probably a bit over a year ago. I remember it well, it's a very nice presentation.

    --
    Move sig!
  41. Spamgourmet? by br0k_sams0n · · Score: 1

    Is it me or is Mailinator a blatant rip-off of http://spamgourmet.com/?

  42. NIO is more scalable by Anonymous Coward · · Score: 0

    In simple tests traditional thread based IO is faster than NIO. On the other hand NIO is more scalable. See this blog: http://weblogs.java.net/blog/sdo/archive/2008/04/more_on_the_sim.html

  43. typek_pb by Anonymous Coward · · Score: 0

    referred pdf seems to be outdated (over 2 years old), not sure whether it is still valid I'd say

  44. Biggest problem of Java IO are ints. by Anonymous Coward · · Score: 0

    Biggest problem of Java IO are ints. More specifically, unsigned ones.

    Lots of actual data files and data protocols have integer numbers (of some size) that are supposed to be unsigned.

    But Java won't let you do unsigned anything. "Use the next larger size!". Well what if you need unsigned long long values? What about having to remember the unsigned nature and convert eternally? (which also gives the problem that you can't override "+" so that you can add two unsigned values together, so have to use unsignedint.add(unsignedint2).

    There's also the problem that in its violent attempt to avoid any system visibility, you can ask for the environment and even update it, but you can't actually change it because it won't affect the current process and it won't pick up the actual environment of the shell the process is opened in.

    If you want $PATH set, you have to use -DPATH=....

    But, and this is the pisser, the documentation doesn't tell you you can't manipulate the environment.

  45. Re: thread resource usage by Anonymous Coward · · Score: 0

    From Wiki page on NPTL threads in Linux 2.6 and higher: "In tests, NPTL succeeded in starting 100,000 threads on a IA-32 in two seconds."

    This is wonderful achievement. However, the memory foot print matter still remains. A thread will typically consume a couple of pages of real memory right off the bat for a runtime stack. Then of course is the matter of how many pages of address space needs to be reserved per thread to allow for stack growth and thread local heap growth.

    So on a 32-bit OS a couple of pages will usually be 8K. A 100K of threads consumes 781MB just to exist and be scheduled by the OS task switcher.

    Using a NIO framework, say, like the Apache MINA, I get a relatively easy framework to program to, couple it to a thread pool (probably 25 worker threads could handle 100K socket connections - give or take a few). The memory foot print from threads is only around 200K.

    Threading is an extremely resource inefficient to scale concurrency - even with the improvements of NPTL (which only applies to Linux OS anyway). Hence why the actor model (which multiplex many actors to just a few threads), coupled with its messaging approach (instead of shared memory that must be locked) has become a popular alternative to a pure threading approach to concurrency.

  46. Re: Disable touchpad by Anonymous Coward · · Score: 0

    -1, O.T. reply to O.T. question:

    1) Find the name of your touch device - $ xinput --list. For my MacBook it's "appletouch".

    2) Find the id of the touch device using the name - $ xinput --list-props name | grep 'Device Enabled'. Don't literally use "name", use the name you found. E.g. My command line is $ xinput --list-props appletouch | grep 'Device Enabled'.

    3) Issue the command $ xinput --set-int-prop name id 8 -d . Where name is the name from #1, id is from #2, "8" is literally "8", and "-d" is literally "-d". So for my laptop at this moment in time it was $ xinput --set-int-prop appletouch 115 8 -d.

    HTH

  47. Thread pool by dna_(c)(tm)(r) · · Score: 1

    I don't really care how Java does it but I would expect they wouldn't always require one thread per socket. This quickly becomes a bad approach on a server application that has more than a few connections.

    Short answer: java.util.concurrent.ThreadPoolExecutor it is available in the Standard Edition since Java 5.0 - very simple to use.

  48. NIO is more than just select... by patniemeyer · · Score: 1

    NIO provides three additional capabilities to Java:

    * select style I/O - managing a bunch of connections with one or more threads (instead of requiring a thread per I/O)

    * direct buffers - allow Java to use raw byte buffers from the native OS without having to copy all of the data into and out of the virtual machine for every operation

    * channels - which have better defined characteristics for interrupting I/O

    Select style I/O is an architectural change to your app that may or may not improve performance depending on your design. Direct buffers are an implementation improvement that will generally improve performance for simple copy operations.

    Pat Niemeyer
    Author of Learning Java, O'Reilly & Associates

  49. NIO is about memory by Anonymous Coward · · Score: 0

    A thread needs memory. If you wan to support a large number of connections, using old school IO will use a large amount of memory. Java stacks are typically 512KB. With NIO you can keep the number of threads low. Performance is not everything.