Linux/Mono are King/Queen for my Server
C# and .NET is free but Windows ….
Yes. If you read my blog. You will think I am a windows fanatic. Well, that’s because it’s the first platform and it’s easy. But seems today easy and comfortable is not enough. When we’re talking about hundred and hundreds of server. Windows can be a bottleneck to your business. Money is the problem. License cost.
I love .NET framework so much, C# language is elegant, async await is beauty. Visual Studio is an awesome tools. A lot of people I talk confuse that they think c# and .net is not free. It’s a shocking experience for them when I tell java or php guy that it’s free. But….
Visual Studio is not Free.
SQL Server is not Free.
Windows Server is not Free.
Ok. That’s fine till now.
With the great power, more feature will come a greattttt…. PRICE.
This become a problem when you have a lot of server. Client is cheap, but server is not. We have to be honest here. When it comes to business, money speak. Facebook, Google, Twitter are using Linux for their server. That’s because it’s free, free of cost and license also free to modify based on their needs. Optimization is the key when it’s come to high performance server apps. You have to understand your tools from the highest level to the lowest level.
I would propose that client development still on windows, because it’s great. Microsoft is always been the best when it comes to UI, DirectX is cool, WPF is amazing. There’s nothing changes in this area. Stick to the Windows on the Client application.
But for the server, I think it’s better to use Linux, because it’s cheap and we can focus on buying great server hardware/machine. License cost won’t kill your business. You can still remain profitable.
A couple years ago I create a software team called Triplelands, we stick using Java on the server side. As the result, you know what ? It’s very painful. After you know c# for so long with all great feature you have to go with ancient language like Java.
Mono is multiplatform implementation of .NET framework and CLR. I underestimate this before when I’m on university. I know it but I won’t dare touch it even see it. I don’t see any hope on that stuff. Till now.
Finally I look Mono again. Xamarin makes me believe that this is something that can evolve. If there’s a big guy behind the tools, we should be feel safe right ?
I look at it a lil closer and it’s turn out that’s brilliant. You can build your apps in windows and deploy it on Linux. Directly. NO need to recompile. Some feature maybe not available, something like windows form, asp .net web form… But I don’t care about that. It’s more than enough. Because I care about building a server, backend not a UI.
Ok. Enough talking. Show me the code.
Linux VM Setup
Now we’re ready to setup a mono. We need to download the Mono 3.
I failed to install the latest tar file. But version 3.0.7 is working. I will try to find the problem next time. But now let’s try the working tar file.
You can follow the instruction from http://www.mono-project.com/Release_Notes_Mono_3.0#New_in_Mono_3.0.10. Just a couple of command.
To make it sure it’s working. Please type mono in the terminal. You will see the message like this.
Because I want to make it easy to version and do build from my source code in the future. I need to install version control. You don’t have to do this if you don’t want to. For windows I will use tortoisehg.
In linux you can find svn and git have already been installed, but not mercurial. You need to install it as a root. Please execute this command to install mercurial.
Hello Async Await for it ……..Demo !
Now let’s do some code. I want to try async await so bad in this demo. So i ‘ve just stolen the the async code from this page. I turn that into console apps. I don’t need GUI on the server.
After finish code, building and test the previous code. We need to create a mercurial repository and make it available to VM.
I want to see that we can run the assembly compiled on windows into linux directly without recompilation. So I will include the executable file into the repository.
Now we need to run the mercurial server so it can be accessed from linux.
Please access your host computer from linux. You will see page like this.
From linux you need to clone the repository.
Please don’t forget to change the permission to the files in linux. The simplest one is to change the mode into 777. Yeah. Silly. But I want this samples to get running as fast as I can.
Ok now we need to check the assembly can running. Just execute this command.
Wow. It’s working. This is HUGE. Async await run directly from assembly compiled from windows !
Ok. Now we want to test building the assembly from the source code in linux. I will use xbuild for this experiment to build the solution. You can think xbuild as msbuild on linux.
Execute the command like below.
It’s success. After that run the assembly like the previous one.
It’s running again. Amazing right ?
Do you have something awesome needs running on Linux ?
Try Mono !