Cassandra, C# and async await.. Oh my

June 11, 2014 Leave a comment

 

Cassandra is really cool stuff. Especially for time series. Even though  you are new to NOSQL the transition is pretty fast once. But first of all you need to learn to unlearn what you know before about relational database.

You need to download it first from DataStax. You can find the step by step installation from here

A couple of things you need to keep in mind is this principle :

 

  1. Don’t model your data. Model your query.
  2. Don’t afraid of data duplication
  3. Denormalization is Good

You also need to be familiar with Brewer’s CAP theorm and BASE.

Ok. Enough talking. Now let’s get down to code.

Cassandra is cool, so we need to find the programming language that’s totally awesome to access it. Smile 

C# it is !!

 

You can easily find the Cassandra library from Nuget. It’s DataStax library too.

 

image

 

The problem is of course the documentation. You can find the sample code from github project actually. Also from here. But dude… it’s still using TPL and ContinueWith callback model.

image

 

Can you imagine if you would try to execute that from loop ? Sad smile

Anders Helsjberg would cry for that one.

What is so hard about changing that one into this one. Everyone will rejoice about that.

image

 

Also I think DataStax need to support Reactive Extensions for their library. Instead of enumerable row it should return Observable.

I saw the another library that support TPL, Async Await and Rx from Nuget.

image

You can found it’s github here. I will definitely check that out later.

 

Until then please spend your time to understand concept, data modeling and architecture in Cassandra. Please read the following books. It’s the latest book that I think will safe you some time when you have a trouble with Cassandra.

imageimageimage

image

 

Have a great time with the pretty Cassandra.

 

Cheers

Categories: Uncategorized

Fix Octave 3.2.4 Plotting Hang Problem in Windows 8.1

November 8, 2013 4 comments

 

For the last few weeks I’ve been following Machine Learning from Coursera. It’s a very awesome website. It’s also FREE.

I learn Machine Learning because that’s a new area that seems interesting in this Big Data World. Until now I think totally our job as software developer is to create application that save our customer data and rarely analyzing it. Of course we provide report but I don’t think that’s enough nowadays.

Machine Learning course use Octave as a programming tools. You can think that as a free and open source MATLAB like program without User Interface. . You can do a lot a computation and prototyping faster there compare to the common programming language as c# or java. But I think for production you need to turn that into real programming language.

The problem I have with Octave it’s a Console Apps. It’s really sad for developer that have been used to Visual Studio for a long time. But we can do plotting from there. That’s really awesome and awkward. Smile But its fun.

The problem I have with running Octave in Windows 8.1 is the plotting windows hang after showing. I search the solution in the internet and finally find two line that solve that Hang problem. Seems that’s a library conflict in Octave

Just need to run this command on Octave CLI.

pkg rebuild -noauto oct2mat

pkg unload oct2mat

 

Reference

http://octave.1599824.n4.nabble.com/plot-window-hangs-td1681494.html
http://stackoverflow.com/questions/12032494/octave-always-not-responding-freeze-when-use-plot

Build on Windows, Deploy on Linux

May 14, 2013 1 comment

Yups.

I think there’s nothing can beat Visual Studio when it comes to .NET development. MonoDevelop like Miguel de Icaza said in this presentation is nothing close to VS2012. But I do interested on where Xamarin Studio will headed.

Developing and Compiling I think still ok on Windows. Just need to deploy and test an assembly on Linux.

So how we do that ? How we transfer that binary to the Linux server. I assume that the server won’t have a UI for performance sake. I think that’s the best. We can fine tune the server for processing concurrent request and not for the fancy UI.

The tools we need is just a simple binary executable and command on Windows. I know this from this blog post.

How to: Copying Files from Windows to Linux via SSH (vice-versa)

We need to download that binary from this page. Just find pscp.exe. Select the latest version. Download it directly.

 

image

As soon as it arrived on your windows machine, just copied it to Windows, so we can execute it from anywhere via command line.

You can use it like this.

pscp C:\Documents\helloWorld.txt username@165.1.122.76:/home/your/destination/folder/

Here’s how I test it

image

And I’m so happy when I see that file is in the server.

image

When you have a lots of files, it’s best to compress it so we can transfer it as a single file. You can use the default compression in windows.

image

Or you can use the 7zip if you are prefer the smaller files.

In this step I will use default windows compression. To unzip it in Linux you need to install it first. Just execute this command to install

yum install unzip

Then execute this command to unzip the file

unzip pics.zip  -d /tmp

 

Very easy right ?

 

Develop on Windows. Deploy on Linux

 

You will got the best from both worlds

 

Cheers

Categories: Uncategorized

FxSharp going Mono

May 10, 2013 Leave a comment

In this blog post I will tell you my experience porting my open source .NET project to Mono. It’s very easy.

FxSharp is my Expert Advisor System for MetaTrader 4 written in C#. MetaTrader is terminal used by Forex retail trader to enter the transaction. There’s a programming language called MQL. You can use it to create your own expert advisor, but it’s very ancient. Procedural and sucks ! MQL 5 is not a big different with MQL 4. It’s a object oriented language using c++ like syntax. It’s not c++. It’s only like c++. You can see a horrible codes written in this language. C# is better for developer productivity. I use Trade Platform .NET to bridge the MQL into C#. It’s very nice open source project.

First, we need to check out the source code from github.

image

Change to the directory and you will find solution file. We will build this with xbuild. Before that don’t forget to change the permission of that source code.

image

After xbuild the solution, you will find that everything is compiled fine.

image

image

But when I run it, i ‘ve got this simple and strange error message.

image

I’m very confused at the first time. Because it doesn’t tell the detail. So I do some googling and found that’s I’m using unsupported API. How do I know which one ?? Finally I found a nice tools called MoMA (The Mono Migration Analyzer)

I download and run it to analyze my application on windows.

image

Include all the assembly tobe analyzed. You can find guide using MoMA here.

image

I take a look at the report and found that there’s a problem in entry point.

image

Seems I use the spesific windows functionality here.

image

Well, I just need to comment it in the caller.

image

I run it again and voila. It’s works. My server is running on linux.

image

Ok. Now I need to connect the Expert Advisors to point to the Linux Servers. First I need to disable the firewall. I don’t want to get caught up setting one by one, so I choose to disable the firewall.

 

image

image

image

Fill the expert advisors settings. And Ok.

image

And… Boom. The program is running but seems it can’t load the assembly required for the process. Trade Platform load the assembly dynamically to App Domain. So there’s something wrong with the loading process I think. Why it can’t find the assembly…

image

Finally I found the problematic codes for loading assembly. It use hardcode to create path for the assembly.

image

I found a good explanation about the best practice for compatibility between windows and linux. Read this article.

 

image

I change the code into something like this. Using method .NET provided.

image

After push and pull from github. Running it. It’s working now !

The Quarts scheduler, parser, tcp/ip. All the functionality.

image

 

It’s very easy to run your .NET application on Linux. Mono is the answer.

It’s awesome

 

Cheers

Categories: Uncategorized

Linux/Mono are King/Queen for my Server

May 6, 2013 Leave a comment

Whaaat !

C# and .NET is free but Windows ….

image

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.

License

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

image

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 ? Open-mouthed smile

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.

Installation

Linux VM Setup

Todo this you need a linux OS. You can get it in virtual machine. I got my VM from Coursera. It’s a great website. You can download a Fedora VM from this. You need a VMWare Player to use it.

Mono Setup

Now we’re ready to setup a mono. We need to download the Mono 3.

http://download.mono-project.com/sources/mono/mono-3.0.7.tar.bz2

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.

image

To make it sure it’s working. Please type mono in the terminal. You will see the message like this.

Mercurial Setup

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.

image

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.

image

 

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. Smile with tongue out

http://msdn.microsoft.com/en-us/library/vstudio/hh300224.aspx

image

After finish code, building and test the previous code. We need to create a mercurial repository and make it available to VM.

image

image

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.

image

Now we need to run the mercurial server so it can be accessed from linux.

image

image

Please access your host computer from linux. You will see page like this.

image

From linux you need to clone the repository.

image

 

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.

image

Ok now we need to check the assembly can running. Just execute this command.

image

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. Smile

Execute the command like below.

image

It’s success. After that run the assembly like the previous one.

image

It’s running again. Amazing right ?

Do you have something awesome needs running on Linux ?

Try Mono !

 

Cheers

Categories: Uncategorized

Xamarin and Mono … You are rock !

May 4, 2013 Leave a comment

I’ve known Mono quite a couple years ago but I didn’t really have a chance to try it out and dig deeper into this stuff. Honestly, when I hear about it, I’m a lil bit skeptical about it. Because back in the day, the implementation is very very incomplete. But now everything is change. And I’m ready to change my opinion too about that. This would be fun.,

Previous week I’ve been playing around and try some nice toys called Xamarin. Do you know what it is ? That’s make c# developer comes true ! You transition to become a mobile developer is very very smooth. Your learning curve is small. Easier to made a great apps and make money of course. Check their website and try it yourself.

 

image

 

If You love c# so bad. You praise Visual Studio a lot. This stuff is for you ! About last week ago they held a developer conference called Xamarin Evolve. I think they will upload this website soon. Check it regularly.

image

Fortunately channel9 able to interview Miguel de Icaza. This interview is amazing. He is a brilliant guy behind Mono and Xamarin.

image

And the things that made Xamarin posible is Mono. I will talk about it later in this blog.

Stay tuned !

Cheers

Are your services scalable ?

April 20, 2013 Leave a comment

Actually I know this for a quite sometimes, but didn’t have a chance to post it.

When we are building service that can be consume by our client apps. We want it to be scalable. Whether it’s a windows service, web service, WCF hosted in IIS etc. But to make the service scalable, we have to know the underlying concept of where the service resides. How the operating system really works. How process and threads are involved in the process.

Everyone is so crazy about the cloud bla bla bla, but seems forgot a tiny things. Operating System concept, Computer Architecture. It’s really needed to build a high scalable and performance service.

I found an interesting talks in Channel 9 presented by the expert Jeffrey Ritcher about threading and it’s really important. Please watch this stuff before you continue read all my opinion.

 

image

 

Have you watch it all ? Great. Take a look at this simple diagram.

 

image

 

This is a very common architecture used nowadays. WPF apps will call WCF services and will then retrieve data from Database then give the result back to the client.

Now my question are ?

Have you create WCF asynchronous proxy for your WPF application ?

Have you use ADO .NET async feature for database connection ?

If you creating TCP/IP Client server application then …

Have you create your TCP client and server asynchronous  ?

Maybe you have already read about Asynchronous Programming Pattern and Event Asynchronous Programming. But you decide to use the blocking API because it’s complex ?

Another thing to learn is to differentiate I/O bound operation and Compute bound operation.

Well. Take a look at .NET 4.5 and c# 5.0. async await feature. Everything async is simple now. A lot of API is async now. You can use it for scalability.

If you are still using .NET 4, you can still using asynchronous programming. Wrap it with task. You can use Microsoft.Async.BCL with Visual Studio 2012 targeting .NET 4.0.

When you think that your code is doing I/O or network operation.

WCF ADO .NET TCP/IP ASP .NET Web API

async it when you can ! don’t tell me it’s hard. it’s there for you to use.

 

Cheers

Categories: Uncategorized
Follow

Get every new post delivered to your Inbox.

Join 1,505 other followers