Hackviking.com He killed Chuck Norris, he ruled dancing so he took up a new hobby…

4Sep/14

Amazon AWS EC2 Linux Swapfile

The Amazon EC2 Linux instances comes without swap. Sooner or later this will be a problem with service hangups or crashes as a result because you run out of memory. I found a lot of instructions on the web about how to add a swap file but no one takes the storage into concern and you may end up paying a lot for a very little performance gain. This article will guide you through swap files on Amazon EC2 linux hosts.

Continue reading...

20Aug/14

SEO Basics

To be honest I had limited knowledge about SEO (Search Engine Optimization). Haven't really spent much time or reflected about it at all. But then I started looking through my Google Analytics info for this site and realized that most of my traffic isn't from referrers, like links or articles I wrote on other sites, but from Google Search. That put it in an whole other perspective for me, and also I started receiving a lot of traffic, upgraded my servers, and realized that some Google Adsense would be in place to pay for the servers. So my thought was to do a series of articles about improving SEO for this site.

Where to start?

If you start searching for SEO on Google you get a lot of information but also a lot of BS. The golden rule here is if anyone promises a specific ranking they are not for real. You can do all you can about SEO but at the same time your competitors might have done a better job.  Start by reading the Official Google Optimization Starter Guide.

You should also, if you haven't already, implement Google Analytics on your site. It's an easy way to track you visitors and views and find room for improvement as well as follow your sites progress.

Google Webmaster Tools is also a very good idea to be able to check how the Google Bot looks at your site. You ranking will be damaged if the Google Bot can't read and understand your site.

More information

Google provides information and recommendations without telling us exactly how the ranking works. The internet is overflowing of people claiming to know something you don't but as I sad before if it sounds to good to be true it probably is! Instead go to the source of the information, Official Google Webmaster Blog.

7Jul/14

Microsoft SQL Server Performance Basics (I/O Performance)

There are a lot of settings that you can tweak to get higher performance out of your Microsoft SQL Server. The most basic one is IO performance, i.e. disk performance. Usually when I talk to people about this I get the response that this is an art form and something that most techs don’t know about or feel that they don’t understand. Most people rely on the SAN team to take care of this but if you don’t understand this and can inform the SAN team what you need you will get the standard. Most SAN system are optimized for  There are always more tweaks that can be applied but in most cases the further you come along this line the smaller impact the changes have. In this article I would like to point out the most basic, and important, performance issues with Microsoft SQL Server that are easy to address. These are independent of size of the solution or underlying hardware e.g. local attached discs or SAN.

Background

To understand why this is so important you need to know a little about how Microsoft SQL Server reads from the disk. To simplify Microsoft SQL Server reads pages, pages contains a number of rows with you corresponding data. The pages with extents are 64kb in size. So the goal here is to read (or write) the page with as few disc IO’s as possible.

Stripe Unit Size

The stripe size is the smallest chunk of data that can be addressed within the RAID. So make sure you are using at least 64KB stripe size. If it’s a larger number like 128KB or 256KB that only means that you can write several more pages in the same stripe, this can actually benefit performance of the read ahead function in Microsoft SQL Server.

File allocation unit size / Disc cluster size

This setting is on the file system level. Microsoft SQL Server is designed for the NTFS file system and the default NTFS disc cluster size is 4KB. Again this should be 64KB for best performance, it enables SQL server to do less IO than a smaller cluster size does. There is a correlation between cluster size and stripe unit size that needs to be meet for optimal performance:

Stripe Unit Size ÷ File Allocation Unit Size = an integer

If possible you should try to meet this formula. However that isn’t always possible due to different storage systems. The most important thing for performance in that case is to use the 64KB cluster size! The formula for partition alignment below is however not optional for performance!

Partition alignment (partition offset)

When I have been talking to people about this most people look at me like I’m crazy. A system that was setup from a clean install of Microsoft Windows Server 2008 and later doesn’t suffer from this, these versions do an automatic alignment of the partition. If the partition isn’t aligned your server will end up splitting the read and write IO into two or more IO’s. This is very bad for performance.

Role of thumb here is:

Partition Offset ÷ Stripe Unit Size = an integer

Old systems prior to Microsoft Windows Server 2008 could end up with a 31.5KB offset (63 hidden sectors * 512b sectors). Doesn’t matter what stripe unit size you have 4,8,16,32,64,128…. It will never make the equation spit out an integer! Therefor bad for performance!

So if your system is prior to Microsoft Windows Server 2008 or have disk partitions created by an earlier version, check the partition offset! It’s easily done by running this command:

wmic partition get BlockSize, StartingOffset, Name, Index

To check the stripe size you have to refer to your storage controller. Standard offset in Microsoft Windows Server 2008 and later is 1024KB and it doesn’t really matter what stripe unit size you have, you will still end up with an integer.

Log files

For SQL server log files you should use RAID 1 both for best read/write performance but also for the extra data security. In a raid one you can lose 50% of your disks without losing data, neither RAID 5 or RAID 10 can guaranty this data safety. It will however cost you half of the storage space.

Do you want to read more?
http://technet.microsoft.com/en-us/library/dd758814(v=sql.100).aspx
Written by Jimmy May, Denny Lee and goes deeper into the techniques.

30Jun/14

Migrate WordPress to Google App Engine

Wordpress on Google App Engine

Why not run WordPress on Google App Engine? You will get performance and stability while only paying for the resources you actually use. Reading the official Google tutorial "Running WordPress in App Engine" it gives you a fare idea what you are in for. But if you want to migrate a currently running site then you have to do some tweaking. So here is a run down on how to do it!

Continue reading...

19Jun/14

Facebook offline

This morning Facebook seemed to be offline! The worlds largest social network was offline worldwide. So far reports has come from the U.K, USA and Sweden witch indicates that this was a world wide error. Currently the site seems to be available for most users and no official information has been posted.

Facebook Offline

Filed under: Facebook No Comments
18Jun/14

Exchange – List all e-mail addresses on domain

Listing all e-mail addresses for a domain on an Exchange server. It's pretty easy from Powershell but it took me a while to figure out so I thought I would share it.

get-recipient | where {$_.emailaddresses -match “<domain>”} | fl name,emailaddresses >> c:\addresses.txt

18Jun/14

Hyper-V – accessing info about physical machine from guest VM

More then once I have run into the problem of not knowing on witch physical server a Hyper-V hosted server is running. Getting RDP access to a clients system and then needing help from SAN or Network teams, there first question: "What physical machine is the host running on?". Without access to the physical servers or System Manager it's hard to know. You could probably figure it out from assigned IP-addresses but there is a quicker way if the Hyper-V Integration Services are installed.

This registry key: HKLM\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters

It contains the following information:

  • HostName
  • PhysicalHostName
  • PhysicalHostNameFullyQualified
  • VirtualMachineName
  • And also additional info about server version etc.

You can also run this from the CMD:
reg query "HKLM\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters" /v PhysicalHostName

If you have remote access:
reg query "\\<machine>\HKLM\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters" /v PhysicalHostName

Ofcourse you can replace the "PhysicalHostName" with any of the above values!

1May/14

Moved site to Google App Engine

Got the last invoice from my hosting company. Wasn't about to pay them good money for another year of services that I'm not satisfied with! So I moved the blog to Google App Engine instead. There is still a few things that needs to be sorted but for the most part it works fine. I will publish a guide for migrating existing WordPress sites to Google App Engine shortly. Followed the official documentation from Google but found a few pitfalls if you migrate existing sites instead of setting up a new one.

This was supposed to be online ages ago but I just moved to a new apartment and got a new job so I had a lot on my plate. But soon I will be back with a lot of exciting projects I been working on.

1Feb/14

Python: Remove querystring from URL

Needed to clean an URL from it's querystring in Python. Found a lot of examples telling me to use urlparse and then put all the bits and pieces back together. An easier and more efficient  way is this:

url = 'http://www.hackviking.com/?var=value'
url = url[:url.find('?')]

url now reads 'http://www.hackviking.com/'

16Jan/14

.Net C#: Webbrowser control print line break

I was updating an old project for a client today. I needed to print a simple list and figured that the easiest way should be to format the data in HTML. Most developers out there has built webpages now days and we all know that it is a quick way to format the information and print it. So after a quick creation of the HTML i found an article named "Displaying custom HTML in WebBrowser control" by Gunnar Peipman. So easy enough to print the custom HTML from the control, based on Gunnar's article I came up with this code:

WebBrowser webPrint = new WebBrowser();
webPrint.Navigate("about:blank");

if (webPrint.Document != null)
{
webPrint.Document.Write(string.Empty);
}

webPrint.DocumentText = printHTML.ToString();
webPrint.DocumentCompleted += webPrint_DocumentCompleted;
void webPrint_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
WebBrowser webPrint = (WebBrowser)sender;
webPrint.ShowPrintDialog();
}

If you don't use the "DocumentComplete" event handler your printout will be blank. In the print I used a basic HTML table to show the data with rows like this:

<table cellpadding="3" style="width:100%">
<tr style="color:White;background-color:Black;font-weight:bold;"><td>Box ID</td><td>Gång</td><td>Hylla</td><td>Nivå</td><td>Nåbar från golvet</td></tr>
<tr><td>10346</td><td>AB</td><td>3</td><td>F</td><td>True</td></tr>
<tr><td>10294</td><td>AB</td><td>3</td><td>D</td><td>True</td></tr>
<tr><td>10296</td><td>AB</td><td>3</td><td>C</td><td>True</td></tr>
<tr><td>10298</td><td>AB</td><td>3</td><td>C</td><td>True</td></tr>
<tr><td>10300</td><td>AB</td><td>3</td><td>B</td><td>True</td></tr>
<tr><td>10302</td><td>AB</td><td>3</td><td>B</td><td>True</td></tr>

When printing data that took up several pages I ended up with this:

pagebreak error

The data was cut of at the line breaks. I Googled a lot and found a few suggestions about css "page-break.." but they didn't have any effect on the webbrowser control print layout. Finally I found a simple soulition, just add a bland column to the left of the table and the line break works. Like this:

<table cellpadding="3" style="width:100%">
<tr style="color:White;background-color:Black;font-weight:bold;"><td> </td><td>Box ID</td><td>Gång</td><td>Hylla</td><td>Nivå</td><td>Nåbar från golvet</td></tr>
<tr><td> </td><td>10346</td><td>AB</td><td>3</td><td>F</td><td>True</td></tr>
<tr><td> </td><td>10294</td><td>AB</td><td>3</td><td>D</td><td>True</td></tr>
<tr><td> </td><td>10296</td><td>AB</td><td>3</td><td>C</td><td>True</td></tr>
<tr><td> </td><td>10298</td><td>AB</td><td>3</td><td>C</td><td>True</td></tr>
<tr><td> </td><td>10300</td><td>AB</td><td>3</td><td>B</td><td>True</td></tr>
<tr><td> </td><td>10302</td><td>AB</td><td>3</td><td>B</td><td>True</td></tr>
<tr><td> </td><td>10382</td><td>AB</td><td>4</td><td>F</td><td>True</td></tr>

Then the printout looked like this:

pagebreak fix