• Anon (unregistered) in reply to Jimmy
    Jimmy:
    If that's the case, then I will submit my grandma's VB.NET WTF's, as she's also technically not a developer.
    If your grandmother isn't a coder but has a manager who instructs her to write VB.NET code, then feel free to submit the result.

    (The problem wasn't just the amusing code, but the reason why the code existed in the first place.)

    Honestly, the real thing that's worse than failure is being sad enough that you have to whine and cry and squeal about how the stories here don't satisfy one's personal quality standard. There's, apparantly, quite a few people who make mere failures look good.

  • Pod Person (unregistered) in reply to Tom
    Tom:
    I think the wtf here would have to be converting server scripts to .NET.

    Honestly, if perl is the best tool for the job, why re-write the scripts?

    Exactly!

    The fact that he is using .NET means the applications are running on a Windows platform (duh...) -

    1. Why in all that is holy would you move an application from Unix/*nix to Windows?

    2. If you wrote your Perl portably, you can install the Windows build of Perl (ActiveState has a nice binary you can load easily - or you can build from source if you are particularly masochistic) and run it on Windows without making changes to your code.

    This, of course, assumes that it wasn't already on Windows to begin with....but if Perl was running on Windows to begin with, then why move your scripts to .NET!!?

    This smells fishy.

    Captcha: ewww My sentiments exactly.

  • (cs) in reply to Pawel
    Pawel:
    If the sysadmin knows perl, he will know the sleep operation.
    Nobody said the sysadmin knows perl. It is possible the perl code didn't use sleep() either.
  • brendan (unregistered) in reply to Will Perdikakis
    Will Perdikakis:
    The code is actually pretty resourceful not a WTF, really.

    He knew what he wanted to do and rather than using the build-in thread function, he used a spin-lock. Lots more wasted CPU cycles, but virtually the same end results.

    The difference is his version, takes 100% CPU time doing nothing, which could otherwise be spent on more important jobs (like serving requests).

    The built in Sleep function interacts with the kernel, and stops the whole thread running until time has elapsed (well that's how its implemented on a UNIX environment).

  • Jon (unregistered) in reply to Sam
    Sam:
    Of course, I'm curious as to why there was a requirement to move all system administration scripts from Perl to .NET in the first place. Why change a working a system?
    Because it didn't have enough enterprise in it.
  • john (unregistered) in reply to webzter

    or drinking coffee out of that same tired mug continually complaining about how many servers they have to support, the number of tickets that were submitted yesterday, and the 8 million reasons he can't get your firewall port opened in dev sometime before 2010.

  • john (unregistered) in reply to webzter

    above post srry

    webzter:
    If s/he's like any good sysadmin I've ever met, they're too busy supporting too many servers and trying to do too many things. They don't have time to learn the ins and outs of a new framework, they're too busy figuring out how to administer the thing the new framework runs on top of.

    lrn2BBCode

  • .NET guy (unregistered) in reply to vt_mruhlin
    vt_mruhlin:
    Not knowing .NET that well, things like this confuse me: Convert.ToDateTime(DateTime.Now.TimeOfDay.ToString());

    It seems intuitive that DateTime.Now.TimeOfDay might already be a DateTime object, so converting it to a String, then back to a DateTime..... ?

    DateTime.Now.TimeOfDay is a TimeSpan object. But if he wanted the current time, then DateTime.Now would have sufficed, it being a DateTime object. Very WTF.

  • .NET guy (unregistered) in reply to ssprencel
    ssprencel:
    Kinglink:
    No, the real WTF is the people here thinking this is ok.

    To explain why it is not ok, this code will use as much of the cpu cycles as it can, Thread.sleep uses minimal cycles. Unless you're running a system with out any other programs running on it. Thread.sleep is the only answer. This is a newbie mistake but it's a pretty major mistake.

    Note: while (current_time > Time_to_sleep_to); where current time is a function call to get the current time in milliseconds is ALSO very wrong.

    No one said the code is ok. We are giving the author a pass because he is not expected to know .NET. He's a sysadmin, not a programmer. In other words, get off his back. :)

    I think we should get ON his back... this is how is easy he could have gotten the Right answer... http://www.google.com.au/search?hl=en&q=How+to+sleep+a+thread+in+.net&meta=

  • BillyBob (unregistered) in reply to triso
    triso:
    Pawel:
    If the sysadmin knows perl, he will know the sleep operation.
    Nobody said the sysadmin knows perl. It is possible the perl code didn't use sleep() either.

    Hey, if you're not going to:

    a) Bitch about how stupid this person is b) Provide an even worse implementation c) Make another stupid comment about the name change of the site d) Begin your sentence with "The real WTF is..."

    then you can move along.

    Plausible explanations have no purpose on this site, sir!

  • (cs) in reply to Will
    Will:
    vt_mruhlin:
    Not knowing .NET that well, things like this confuse me: Convert.ToDateTime(DateTime.Now.TimeOfDay.ToString());

    It seems intuitive that DateTime.Now.TimeOfDay might already be a DateTime object, so converting it to a String, then back to a DateTime..... ?

    Exactly, it's a waste of time...which is the point. It keeps the thread busy until the specified time has elapsed.

    Actually, no. The "waste of time" to which you're alluding happens before the loop.

  • Sam (unregistered)
    Whitey:
    "3) Using a 100% CPU utilization loop to "pause" the system. Hooray. (idiot) "

    To me, this is the real WTF. Lets ask the system repeatedly: what time is it?convert to double, compare.. what time is it?convert to double, compare.. what time is it?convert to double, compare.. what time is it?convert to double, compare..

    I like to call it the "Are we there yet?" algorithm.

    john:
    lrn2BBCode
    Or just use the "Preview" button...

    By the way, I'm not the Sam who commented earlier in this thread. I'm the Sam who gloats about not telling you what my CAPTCHA is. Muhahaha! Damn, that's why you should never gloat...

  • Jazz (unregistered)

    Oh come on! Clearly this code was meant to be part of a load-testing system. You would run the CPU for different lengths of time at 100%, and measure how long it took for the CPU to overheat, thus providing you with a baseline thermal curve against which to tune your cooling systems. In fact, you could run this across an entire server farm to test the response of the air conditioning unit in the data center.

    Zak says, "To be fair, the guy who coded this is technically not a developer. The interesting thing is that he figured out how to stop a windows service via code..."
    That's not difficult. Most windows programs and services stop on their own, randomly, using their own code.
  • dp.design (unregistered)

    I wrote some Java that was nearly identical to this (except, you know, it was in Java) when I created a Power Hour buzzer in my freshman year of college. About 10 minutes into the event, the CPU fans would sound like jets preparing for takeoff.

    I still have the source. I'm not sure why, but I feel compelled to post the relevant snippet:

    theConsole.putln();
    			theConsole.putln("Ready to begin.  Press enter to continue!");
    			char enter = theConsole.getlnChar();
    			Calendar theTimer = new GregorianCalendar();
    			int startTime = theTimer.get(Calendar.SECOND);
    			
    			java.awt.Toolkit.getDefaultToolkit().beep();
    			java.awt.Toolkit.getDefaultToolkit().beep();
    			java.awt.Toolkit.getDefaultToolkit().beep();
    			
    			theConsole.putln("Drink!");
    			int roundsDone = 0;
    			int theMinute = theTimer.get(Calendar.MINUTE);
    			while (roundsDone < eventLength)
    			{
    				Calendar currentTime = new GregorianCalendar();
    				int currentSecond = currentTime.get(Calendar.SECOND);
    				int currentMinute = currentTime.get(Calendar.MINUTE);
    				if (theTimer.get(Calendar.SECOND) != currentSecond)
    					theTimer.roll(Calendar.SECOND, true);
    				if (theTimer.get(Calendar.MINUTE) != currentMinute)
    					theTimer.roll(Calendar.MINUTE, true);
    				
    				if (theTimer.get(Calendar.SECOND) == startTime && theMinute != theTimer.get(Calendar.MINUTE))
    				{
    					theConsole.putln();
    					theConsole.putln("One minute has elapsed!");
    					
    					roundsDone ++;
    					String currentLocation = "Currently on minute " + roundsDone + " of " +eventLength;
    					theConsole.putln(currentLocation);
    					
    					theConsole.putln("Drink!");
    					
    					java.awt.Toolkit.getDefaultToolkit().beep();
    					java.awt.Toolkit.getDefaultToolkit().beep();
    					java.awt.Toolkit.getDefaultToolkit().beep();
    					
    					theMinute = theTimer.get(Calendar.MINUTE);
    				}
    			}
    			theConsole.putln();
    			theConsole.putln("Event concluded!  Congratulations!");
    			theConsole.putln("Press enter to quit.");
    			char exiter = theConsole.getlnChar();
    			System.exit(0);

    CAPTCHA: This code is even shittier than Taco Bell tacos.

  • CodeMonkey (unregistered)

    Okay, converting DateTime.Now.TimeOfDay to a string and back to a DateTime aside... I bet this code hiccups once a year: when it goes to sleep before "falling back" to DST and then wakes up before it went to sleep.

  • Greg (unregistered) in reply to Dr. Advil
    Dr. Advil:
    Calling Thread.sleep() would allow other threads to run and may subject your current thread to undesired behavior via a scheduler that you have no control over.
    Actually, that'll happen with or without Thread.sleep(). Thread scheduling is pre-emptive in most modern systems.

    It's generally considered a "good practice" not to busy-loop your processor.

  • anonymouse (unregistered) in reply to RON
    RON:
    Mio:
    RON:
    The entire function can be shrunk down to this, by the way:
    Thread.Sleep( TimeSpan.FromSeconds( seconds ) );
    

    sigh

    Or

    System.Threading.Thread.Sleep(seconds * 1000);

    Why bother instantiating a TimeSpan object?

    Because

    A) it's more readable B) it doesn't require you to memorize the fact that Sleep requires milliseconds C) If you're concerned about micro-optimizing a call that will subsequently put the system to sleep for a long time, your priorities are out of whack, D) and finally, it's a structure type whose only internal value is a single 64-bit integer, and the act of instantiating it is roughly the same amount of work as multiplying a time value by a magic number (1000).

    TimeSpan.FromSeconds is a static/shared function and therefore is not being instantiated

  • (cs) in reply to anonymouse
    anonymouse:
    TimeSpan.FromSeconds is a static/shared function and therefore is not being instantiated

    FromSeconds has to create a TimeSpan object to return.

  • Rob Sirloin (unregistered) in reply to BillyBob
    BillyBob:
    triso:
    Pawel:
    If the sysadmin knows perl, he will know the sleep operation.
    Nobody said the sysadmin knows perl. It is possible the perl code didn't use sleep() either.

    Hey, if you're not going to:

    a) Bitch about how stupid this person is b) Provide an even worse implementation c) Make another stupid comment about the name change of the site d) Begin your sentence with "The real WTF is..."

    then you can move along.

    Plausible explanations have no purpose on this site, sir!

    Amen!

    (The new name sucks:)

    -RS

  • bla (unregistered) in reply to Jimmy
    Jimmy:
    "the guy who coded this is technically not a developer"

    If that's the case, then I will submit my grandma's VB.NET WTF's, as she's also technically not a developer.

    If he develops code that then gets put into production, then he is technically a developer, no matter his background. As such, he is eligible to have his code featured here.

    I mean, why would we let people get away with writing wtf-y code just because they have the wrong background?

  • Hexar (unregistered) in reply to poochner
    poochner:
    Cheatz:
    Processors are bought with a purpose: Put them to work! Use those cycles!

    Q: Why are you running {Seti, or whatever} on this box?

    A: Idle cycles never come back.

    MANA REGENS DPS DOESN'T!

  • formersysadmin (unregistered) in reply to Sam
    Sam:
    This is, quite frankly, a stupid script. It would have been a stupid script had it been written similarly in Perl. The correct function to call, "sleep," is the same in both Perl and .NET. And a search on Google for "sleep vb.net" brings up a code sample for the first link, just as doing a search for "sleep perl" brings up the definition of the sleep function in Perl! Finally, after running this script the sysadmin should have seen the CPU peg and realized that it was a stupid script.

    I would hope this is a junior sysadmin that was suitably educated in how to use library functions and Google.

    Of course, I'm curious as to why there was a requirement to move all system administration scripts from Perl to .NET in the first place. Why change a working a system?

    sleep(perl) takes seconds. sleep(CLR) takes milliseconds. What do you do when you say "sleep 20" and then it comes back pretty much instantly?

  • (cs)

    If most developers cannot even grasp multi-threading programming properly, how much does one expect an administrator to achieve?

  • (cs) in reply to bla
    bla:
    Jimmy:
    "the guy who coded this is technically not a developer"

    If that's the case, then I will submit my grandma's VB.NET WTF's, as she's also technically not a developer.

    If he develops code that then gets put into production, then he is technically a developer, no matter his background. As such, he is eligible to have his code featured here.

    I mean, why would we let people get away with writing wtf-y code just because they have the wrong background?

    Perhaps because people quite often get told to do things they were not hired/trained for?

  • D (unregistered)

    This comment is overdue but I saw something just as bad in PL/SQL... sure customers complained, heads rolled, but the code was fixed to this psuedocode:

    try to sleep... no? ok... while (timenow < timewewant){ <-- yes this is the actual code } success!!! yaaay!!!

    So being in pl/sql, this would halt the customer's production server very severely... and since this was used in a "bussy" loop, something terribly terrible was on the horizon for my company!

  • Hath1 (unregistered)

    OK, everyone missed the obvious reason he did it here.

    He was made to change it to .NET against his own better judgement.

    Later, they will complain about the performance of his script.

    His reply: ".NET is much more resource intensive than Perl. When we did this in Perl it used almost no resources at all."

    Captcha facilisi: He's hoping his reply will facilisi his being able to return to using his Perl scripts.

Leave a comment on “Getting Better Sleep”

Log In or post as a guest

Replying to comment #:

« Return to Article