Monday, 22 January 2018

C++ Simple Limits & Server Recase

Health & Myself
What a whirlwind few weeks I've had, first of all, I've had some minor medical work done so not really been in the mood to do anything very interesting except recuperate in my spare time.  I've also got on-going dental treatment going on, so I'm doubly aggravated.

Next I have been so busy with work, I've had a change of job title, I've been effectively promoted into the lead developer role for the platform/product range I work on; this is sort of a defacto position, as I'm the ONLY developer working in this area at present, however I'm now officially the man on point and am about to reform a new development team around it.  I will be working in Scrum methodology with this new team, we'll be pushing product to both Windows and Linux, Git will be our source control system (no matter what anyone else says) and I'm going to leverage C++ as the core product with tools all being produced in Python, very exciting stuff.

Server Issues
At home however, you may have seen this late night  problem....


I have not, as yet, tackled this problem in any satisfactory manner; there's just been too much going on.

However.... I have a plan, a plan so cunning you could put a tail on it and call it a fox.

I had a look around in the case, and removed the bad drive, here it is....


This is an old drive first of all, and it was only 3.0gb/s SATA, but it was useful as part of my mirror, and without it I'm now naked.  In my room/workspace tidy rambling video you will see I have a stack of WD blue drives on my desk, however I'm at pains to put them into this server, as the more space I give myself then the more data I have to move later, and the less places I have to stash that data.

What do I mean?... Well, that machine already has about 4TB of data in the two ZFS Pools and the one scratch drive, I do not have ANYWHERE else to put 4TB of data, and I can't afford a new drive, hence why I've carefully and strategically informed the wife I'm buying the off 1TB drive once in a while over the last year... Dropping a 4TB drive in the mix, she'll flip.

Recasing my Server & Workstation
So, my plan?


Well, first of all I have my main work station in a trusty, but now rather old, Coolmaster Cosmos 1000 case (you can see this case in some of the very early pages of this very blog)... Now, this is a very nice case, and has 10 internal 3.5" drive bays... So would be pretty nice for my server to move into, add all the new WD drives to it and voila a working server with expansion capabilities.... A recasing, that's a plan... Plus I get to perhaps look at that Xeon mod a year on and evaluate how it got along.... And of course more ZFS fun... Maybe a video about Git & setting up my own ticket handling system.


Right, that's the server... What about the now case-less workstation?

Well, I'm considering a new case, of course.  Front runners are the Corsair Obsidian 750D as it has modular upgrade ability, and if I like it, I can get another and expand the server into it next year.

Infiniband
A long-term project is to consider an Infiniband link between my server and my workstation, we'll see how this goes along, not only would I need to purchase some adapters and cables, but I would need to switch my workstation into a new dual-boot as only Linux would be on Infiniband (and as you may have noticed Windows was on the list of platforms for my new role specification).

C++
Simple limits in C++?.. What am I talking about, hmmm, well I just ran into some code:

auto value (0);
if ( requisitValue < defaultValue )
{
    value = requisitValue;
}
else
{
     value = defaultValue;
}

Nothing wrong with this you may argue, however the developer hadn't looked at the values they were working with, the defaultValue for this system locale was ALWAYS the highest value on a sliding scale, the configuration insisted the default be the cap and so any requisite value would be smaller.

I asked the chap to have a think about this code, having explained the requisit would always be lower than the default, and asked him to come up with any improvements.  He did....

auto value(
  (requisitValue < defaultValue) ? requisitValue : defaultValue);

I asked him to rationalise this change, why had he done it?


  • To meet the coding standard define of not assigning, but to initialise with a value
  • To make the code less lines of code
I have no disagreement with the first point, the second... Not so much....

I do not subscribe to needing code to be smaller (less lines of code) so long as it's readable, as for my work maintainability far out reaches using less lines of code.  Especially when the change made is exactly the the same resulting code, just the change is far harder to read.


(Don't miss-read this, I agree you should try to make functional code take less lines of code, but the above is white-space more than functional change, white-space on a modern compiler is NOT a problem, make your code readable before you start trying obfuscating functionality for fancy frills).

I stopped the developer in his tracks however, and asked him to pull up the document for the specification and describe "defaultValue"... "The maximum amount allowed in the value" he read.

So, changing the name of this value was the first step it became "MaximumValue".  Use a meaningful name.

And finally, if you really want this decision to be a single line of code, how about:

auto value(
    std::min<valueType>(
        requisiteValue,
        maximumValue));

Using the minimum function here, we make it clear we're doing a mathematical operation, it's a single line instruction (even if I do stagger it for readability over four), and we're not going to confusing the order of our parameters, so avoid introducing comparator ordering bugs later.

This is the simplest way to find a limit between two variables of the same type in C++, using std::min and std::max.  Learn about them and love them.

The reply the young man gave me... "But changing the name'll mean I have to change hundreds of different places in the code!".... "Yes, so use find & replace in files?".... "Oh but what about all the other "defaultValues?".... "Why are they not in namespaces, or classes, or using other names?"... Silence.

Tuesday, 9 January 2018

Water Cooled PC's... The last harbour of the Elite System Builder?

Simply put... No, no I don't... And this isn't just some trifling aversion, I mean I have a real deep rooted problem with going and putting a water reservoir inside a machine, this is even before we consider the logistical challenges to installing a water loop.  Lets delve deeper....

Traditionally PC's, and indeed most computers, have been air cooled, initially machines were pretty slow meaning the surface area of the chip alone was sufficient for heat dissipation (my 68000 equipped ST's for example).

However, as machines got faster so the electronic head began to build, essentially the more power the machine uses literally the more heat is put off, in the broadest sense thermodynamics demands that electrical energy moving the electrons inside the components not be 100% efficient and therefore some of that energy be lost, and it's only escape is as heat energy.

This was dealt with by the addition of extra surface area to chips, in the form is heat-sinks, many finned metal constructs stuck on, simply to provide the added folders of more surface area, indeed some components - or whole systems - can be cooled this way quite well.

Things never stay still, so as Moores Law gained traction into the 1990's fans were added to many systems to draw cool air in and over the components, specifically the processor or CPU, which is where I found my first system fan, on my Intel 480 DX4-100 chip in the mid 90's (prior to this my 486 SX-25 was still passively cooled, with just a heat sink!).

Since then the fans in my system have evolved over and over, and as a bachelor I had no issues with massively loud fans blowing or whirring systems... This is just what you had, usually tiny fans spinning incredibly fast, plus hard drives etc, PC's made a hell of a clatter in the late 90's and early naughties.


Enter the wife to be, and things had to change, so I looked at quietening the systems I use down:


And it became a bit of a tradition with each iteration of my work area to improve the sound aspects, even on systems not kept directly in my working area:


So now I have a happy-and-successful train of experience with both Knix, Sharkoon and Noctua fans, all excellent in their ways, I have experience with drive ordering, switching SSD's, orientating my power supplies, smoothing dust filters... The systems I run close to me are whisper quite, yet extremely powerful, and never get too loud, my typing is always the loudest thing around!

Water cooling however is "silent".... Erm, reality police, no it's not.... You still have the sound of a power supply unit in your machine, and unless you're absolutely crazy you don't really open them up and try to passively cool them, so it will have a fan in there.  I can switch the fan out for a silent brand, voiding any warranty, but really is it going to be silent?  No, of course its not.

So, what do I gain with water cooling?  Really, what do I personally gain?

  • Worry about the joint fittings
  • Pump seal
  • Block corrosion & blockages
  • Coolant contamination/algae growth
  • Tube decay
All leading me to think about catastrophic failure, which is coolant, be it electronic safe or not (most likely not) spilling out everywhere, literally hosing my machine.

What do I get with a fan?  A high temp warning, or an indicative sound, and the chance to clean things up with a blow of air!... Air, not water, air, not worry.

And I'm going to sit like this forever I think, I see JaysTwoCents, I see ScienceStudio, I see Linus Media Group and a plethora of other skilled and knowledgeable folks on YouTube and at large vaunting water cooling all the time, but truth be told... I can't ever help but wonder if this is just folks looking for someway to express just how superior they are to others.

Lets face it, the PC master race exists, we're here... And some of us have been on the band wagon a long long time*, and it's the need in us to express this that I think is this very trait driving this die-hard gamble on water-cooling.

Anyone, and I mean anyone, can build a modern PC... You literally buy the parts and slot them together like the ultimate in expensive Lego... The elite caché of being able to do this once highly skilled and technical task has been ebbed away, the fire was literally stolen from us and passed to the masses.

What therefore do those of us, whom endured being the nerds and the geeks and the outcasts so long, turn to in order to almost prove our superiority, how to we edge the masses back out of the picture?  Well, I think that's water cooling**.

Water cooling is nothing but a risk, you can't scale it, you can't use it in production, you can't easily maintain it, and the ultimate common denominator is spillage, that liquid does not want to stay in that loop... Where as air is ubiquitous, your kit can cope with being submerged in air all the time!

The final incarnation of this is perhaps the most perverse in "ultimate", to exclude the masses and that is the niche phenomena of submerging a PC in mineral oil... As seen here...



The ultimate irony of this entertaining video being the CoolMaster*** sponsorship at the beginning, being for a CPU water cooling kit... CPU only, not scaling to the GPU as well... and vaunting "silent" fans... Just put the damn silent fans in your case, on your CPU, let the air do the job...

You can argue with me about the thermal properties of water being so much more than air, meaning you can "push your hardware further, faster than before", that maybe so, but it's again an edge case, you can over-clock on air, and if you're buying a new system to overclock you're falling straight back into my master-race theory, you're striving for more than the public can reach, you're pushing the envelope, you're ultimately trying to be more interesting than you actually are...

Good luck, really, truly, good luck, I can't wait to see your video posts about it, and I will watch with baited breath.  However, my breath will ultimately be passing through and cooling an air cooled machine, as it's simply safer, easier and more maintainable, and I'm not worried about being boring or proving anything.





* Anecdote of the day, one kid at school found out I had an Atari ST, and he offered to "Swap you a Neogeo with Contra for it right now"... I laughed in his face, I in fact looked at him like a cockroach; as he was being nasty; "do you think all I do is play games?"  He had no concept of using a piece of electronics beyond plugging it in, I was creating.  I went home each night and I tinkered with STOS, later I tinkered with Pascal, and I'm paid to now tinker with code all day... I don't think that lad is paid to play his Neogeo, or any other console, and no it's not a twitch streamer - I've looked.



** I have a very similar theory as to why very boring people get a piercing or a tattoo, they've no idea what it means, nor any idea why, but they can't help but point it out... Imagine a 1990's computer geek getting a skull tattoo on his face... Same thing with water cooling.



*** I love CoolMaster cases, but I never want to touch these kits....

Saturday, 6 January 2018

World Cup 2018 Group First Leg Predictions

Before all the Octopi, Squirrels, Cow-Pat Bingo and whatever else gets rolled out for the Football (yes, not Soccer folks) World Cup in Russia I thought I'd give you my game by game predictions... It might be worth an accumulator?  But you may just find lots of my own personal bias.

Group stage - First 16 Games Predicted...

Game 1:  Russia v Saudi Arabia - Russia 2 to nil, as hosts I think they stand a real chance to put a stamp on the game.

Game 2: Egypt v Uruguay - Egypt 1, Uruguay 1 - I feel that Egypt have some talent for them and this will over arch Uruguay's historic tenacity.

Game 3: Morocco v Iran - Morocco 1, Iran 0 - This is a pretty even match in my opinion, however, I believe Morocco will pip it.

Game 4: Portugal v Span - Portugal 1, Spain 2 - Very hard to pull this one, it's going to either see lots of goals or not very many, but I'm going to edge Spain over the Portuguese as they'll want to put a mark on the score card against their regional adversaries after the Spanish turmoil of 2017.

Game 5: France v Australia - France 2, Australia 0 - I'm sorry to say I don't think this'll go anywhere except France's way, Aussie still rules!

Game 6: Argentine v Iceland - Iceland 1, Argentina 0 - As the chap whom has helped save the wife's life from cancer is Icelandic, I'm voting with my heart and my hopes.

Game 7: Peru v Denmark - Denmark 2, Peru 0 - I've got to say the Danish will enjoy this one, with no real rivalry on the international stage I can only say this may feel like one of those  wonderful friendly world-cup matches.

Game 8: Croatia v Nigeria - Croatia 1, Nigeria 1 - I think things maybe slightly swayed on the Croat side, but Nigeria squad isn't to be sniffed at, pulling things even.

Game 9: Costa Rica v Serbia - Serbia 2, Costa Rica 0 - One of those one-sides group matches, but I believe the Costa Ricans won't let the Serbs have it all their own way.

Game 10: Germany v Mexico - Germany 3, Mexico 1 - My git feeling is of course for German dominance, however I don't think Mexico will let it go into a Teutonic slide.

Game 11: Brazil v Switzerland - Brazil 2, Switzerland 0 - Very one sides I'm afraid, though I think the Swiss will play good structured football.

Game 12: Sweden v South Korea - Sweden 2, South Korea 1 - I actually think this maybe nil nil in the full-time mark, but if I'm taking my head at true value Sweden should pull through.

Game 13: Belgium v Panama - Belgium 2, Panama 0 - The Belgians, if they can hang together as a team, will walk over the tiny Panama offering, however it'll again be a friendly feeling game.

Game 14: Tunisia v England - England 1, Tunisia 0 - We English will probably cock this up mightily, giving everyone at home heart failure to just about pull a head.  However, if the English score early they'll go off the boil; as we always do; and there's potential for a real upset.

Game 15: Colombia v Japan - Colombia 2, Japan 1 - I think the Japanese will play well, however can they over come the South American side?.... I'm not certain.

Game 16: Poland v Senegal - Poland 1, Senegal 2 - I think the African side will push up forcing the Poles to equalise, but there'll be a last minute push from one or the other, I'm very split on this it may go even, but ultimately I think it'll be down to whom is most hungry.


That's the end of the first match in the Group Stages from me, more will follow...

Friday, 5 January 2018

Bad Code...

You know when you open someones code and you find this inside a class function...

unsigned short currentMessageOffset = this->CurrentMessageOffset;

That you're in for a rough ride.

First of all, WHY assign the member value on the right to a local?  No-where else in the class is this value edited or read, so there's no need to assign it to anything.

And then the naming, this naming of something local with the same name, and it is the same name, despite the capitol leading letter, it's the same name, just makes this utterly useless.

All this before even mentioning that the code is an assignment not an allocation, so annoying.

Wednesday, 3 January 2018

Ultra Cheap ZFS Array

Make your own ZFS array (mirrored) with USB Flash drives, for cheap!



Since this... interesting post of mine... has only about 10 views, and my tech items usually get a few hundred, I figure somewhere along the lines it got trampled by my silly New Years post....

Monday, 1 January 2018

Alright, alright, here it is....

Happy New Year...



Now fuck off and stop saying I'm not festive!

Sunday, 31 December 2017

Using Flash Drives in ZFS Mirror

This post comes from an idea I had to allow me to easily carry a ZFS mirror away from a site and back again, we didn't need much space - only 5gb - but it had to be mirrored in triplicate, one copy to stay locally, one going into a fire safe on site and the third to be carried by the IT manager off-site each evening.

The trouble?  A near zero budget, so for a little over £45 we have a 14GB ZFS mirrored pool, across three 16 GB USB Flash drives and one three port USB 3.0 hub.

It was perfect for the task at hand, extremely portable, and cheap, I thought the same approach may help anyone trying to get to learn a little more about ZFS, a student or even someone using a laptop as a small office server - as the laptop literally has its own battery back-up system built in!

It's not the fastest solution, its in fact extremely slow, but as an entry step it's perfect.

See the full video below, throughout the commands I list were in use...



Commands:

Listing Disks by ID...

ls /dev/disk/by-id

Listing Disks to a file for use in a file script as you see me using...

ls /dev/disk/by-id -1 > disks.txt

------------------

To install ZFS on Debian/Ubuntu linux:

sudo apt-get install zfsutils-linux

------------------

To remove & purge ZFS from your system:

sudo apt-get purge zfsutils-linux

(and you will be left with "/etc/zfs/pool.cache" to remove or back up yourself).

------------------

Command to create the pool...

sudo zpool create <Name> mirror <DiskId1> <DiskId2> etc...

The name we had here was "tank", if you already have data on these disks you will need to add "-f" to force this change through.

------------------

Command to make a file executable - like our sh script:

sudo chmod +x <filename>

------------------

Zpool Commands:

sudo zpool status

sudo zpool import <name>

sudo zpool scrub <name>

sudo zpool clear <name>


You will want to "import" if you completely remove ZFS or move one of your sticks to a new machine etc, simply insert the disk and import the pool by name.

Scrub will be used whenever you return a disk to the pool, remember the point here is to allow you to replicate the data across the three sticks and be able to remove one or two to safe keeping, be that an overnight fire safe, or taking a physical copy with oneself.

Clear is used to remove any errors such as the Pool becoming locked out for writing - which it may if a drive, or all drives are removed - you simply clear the current problem with any pool.


Summary:  Remember this is NOT the optimum way to run ZFS, this is actually extremely slow, you are replicating each write over your USB, you can only cache so much in the RAM, but it is not a performance piece, this is about ensuring one replicates data for safe keeping, a small office or your dorm room server setup could be completely provided by a laptop in this manner, it has it's own battery backup, it is quite (if you get the right machine) and really this is a very cheap way to play with ZFS before you move onto other bigger hardware options.  Plus, I find the best way to learn about technology is to break it, even a little, and so constantly breaking down your pools by pulling USB sticks out of them is an excellent opener to recovering your pools.  Play about first, don't put anything critical on there until you're really happy with the results.

For an excellent post covering creating ZFS pools, cheak out programaster's post here: http://blog.programster.org/zfs-create-disk-pools

And for the official ZFS documentation you can check things out with oracle here: https://docs.oracle.com/cd/E26505_01/html/E37384/toc.html


Oh, and Happy New Year... I guess I made it to 100 posts this year...