This post is very old. Please bear in mind that information here might be incorrect or obsolete, and links can be broken. If something seems wrong, please feel free to comment or contact me and I'll update the post.
A few weeks ago, I switched my development environment from Windows to Linux, on a project which was developed so far on Windows only. In this post, I want to describe the issues that brought me to this switch, a short overview how I did the actual port, and some observations on Linux for developers. This is the first post in a series of at least two, the second post will describe the tools I use on Linux right now.
Background
The project I’m working on is written in C++, with some Python tools mixed in. My original development environment was Visual Studio 2005 on Windows XP. This is already the first issue: Updating Visual Studio or Windows is not trivial, as both the OS upgrade as well as IDE updates require new licenses, and especially in companies new versions are not bought immediately.
The problems became apparent when I tried to multi-thread parts of the application. At the core, it’s doing a lot of number crunching, in small work blocks which can be processed independently. As I couldn’t use OpenMP due to dependency issues (a 3rd party library could not be linked when OpenMP was enabled), I was threading manually. Unfortunately, the application had to allocate some memory in each thread, and as it turned out, the scaling on XP was catastrophic. While I did get a speedup from 1->3 cores, it became slower from 3->4 – clearly, I was hitting some issues with either the scheduler or the memory subsystem, as my code didn’t have any I/O in it.
A quick try on Vista showed that the same application ran more than twice as fast, but unfortunately, I couldn’t install my IDE on Vista as well, and developing on Windows XP and testing on Vista was out of question. Again, with a free IDE, the change would have been no problem (and the express editions don’t have x64 support*, nor OpenMP, more on this later. * See below for an update!).
On the other hand, getting a recent Linux with a recent compiler was not a problem. With Wubi, Linux can run side-by-side with Windows while giving you a full Linux based development environment. Running side-by-side is especially important when you’re in a corporate environment, as you usually cannot simply erase the disk and install Linux without making the IT angry.
Linux
I used Wubi, with the Kubuntu flavour, as I like the KDE environment a bit more than GNOME – especially as I use Qt for UI development now. Specifically, I used Kubuntu 9.04 x64, while I used a x86 Windows XP previously.
Porting
I started by checking out the code from SVN, so no problems here. Even though the application was written in standard C++ and didn’t depended on Windows-specific functionality, it was built using Visual Studio project files and used a few WinAPI calls. As a first step, I ported everything to CMake – something I could/should have done on Windows already. With CMake, I was able to quickly convert one project after the other, and immediately check for compile errors. This proved to be the best way, as I never came into the situation where I would get huge amounts of compile & linker errors at the same time; I had that when I moved an already CMake based project from Windows to Linux and tried to get it running in its entirety. During porting it’s best to port on subproject at a time, even if the project is originally using a portable build system.
As I mentioned, I used explicit threading on Windows, which I replaced by OpenMP on Linux. Now I could also throw out all configuration stuff for threading; among other things, I wouldn’t have to reduce the priority of my application on start-up – this was necessary on XP, as the machine would become unresponsive during processing otherwise. Boost.Threads might have been a valuable alternative here, but OpenMP is well suited to the kind of loop-parallelism I had in my code, and even simplified it compared to the explicit splitting/execution I used previously.
For graphics, I was already using OpenGL. As I could easily get the nVidia binary drivers running, I had no trouble on this side. Overall, it took me half a day to port, including the time to set up the Linux installation.
Results and some thoughts
The net result is interesting: The same application is running 5-10x faster now when using all four cores, so porting to Linux was really worth the hassle. I assume that with Visual Studio 2010, running on Windows 7, I would get similar performance, but the key point to take with you here is: Getting your stuff to work on Linux only costs you time, and not too much if you are a bit careful. Using CMake on Windows (or another portable build system), writing more or less clean C++ and using portable libraries makes porting to Linux easy, and the switch itself is not too complicated. At the moment, the tooling on Linux is reasonably comfortable (more on this in the next post), and the “pain factor” to switch from Visual Studio to for instance KDevelop or Eclipse CDT is no longer there.
Actually, the switch is so simple that Microsoft should get concerned. For instance, I have been developing mainly on Windows since several years, and I occasionally tried Linux, but I never did a complete switch due to various smaller and bigger problems. However, since 1-2 years, the Linux desktop, together with the tools, is good enough to provide some real benefit, especially if you cannot access the latest Microsoft products. Microsoft used to have the best developer tools by far, and quite stable APIs, which were in my opinions the corner stones of their success. However, they’re changing APIs now rather quickly (WinForms? WPF? WinAPI?), they provide new platforms which require rewriting your applications (I’m still waiting for an application like AutoCAD which has a C# UI and a C++ backend), and the tool release cycle is simply too long – waiting 2 years to get a compiler bug fixed is just ridiculous.
On the other hand, developing on Linux means you have an extremely stable API (POSIX isn’t going to be replaced with PoseFX, for instance), the UI side is rather clear (GTK or Qt, you choose), and the tools are getting better as well (GCC and LLVM are getting better quickly, and installing a new GCC does not require buying a new license). If Microsoft does not turn around the ship with Visual Studio 2010 and some clear statements on the APIs, I assume that more and more developers will find that Linux can be also a very nice environment. Again, more on this next time!
[Update] A few notes, as this article is getting a lot of attention and there are some misunderstandings. Regarding the library, I had access to the source, and I could have built it on Windows — it’s simply very time-consuming, as it depends on many libraries like zlib, which I would have to compile with the new settings on Windows as well. Getting these dependencies on Linux is obviously much easier.
OpenMP vs. manual threading: This did not improve the performance compared to the manual threading, but it was a nice bonus as it cleaned up the code a bit. On Windows, I could not use OpenMP due to link issues. The other bonus came from the switch from x86 to x64. Finally, the Linux memory allocator is much better in multithreaded environments, and this was the biggest performance improvement. In total, the application runs several times faster now, without changes on my side.
Summary: In this particular case, the switch to Linux took me just a few hours, while the benefit for me was rather big: Improved performance, and less hassle with dependencies. The drawbacks — getting used to Linux, different tools — are out weighted by the advantages for me; and that’s the main point of this blog post. I was surprised how easy it was to switch from Windows to Linux completely on this project; as I expected a lot of problems (like for instance, not being able to get the stuff running at all!)
Things might have been different if the library and the dependencies would be easier to build on Windows, and I would have gotten access to a new Windows version/new compiler version, but this is simply how things turned out, and I don’t miss my Windows setup at work.
[Update] The x64 editions of Visual C++ Express require some setup to support x64, but it is possible to add x64 support manually using the compilers from the Windows SDK. Check out the official C++ Express feature list and a guide how to enable x64.
Related posts:
@Nitin Reddy Katkam
So use Java or if you don’t like it, use Python, Perl, Ruby, Php. The world is so much larger then .NET and C/C++. Of course I don’t know what projects you are doing, but if it isn’t for embedded devices that there is no reason at all to be “glued to just one operating system” (of course it is, if you stay with MS tools).
Thank you for censoring my comment, but again, to your update:
> [Update] The x64 editions of Visual C++ Express require some setup to support x64, but it is possible to add x64 support manually using the compilers from the Windows SDK.
Not true! Visual Studio 2008 Express Edition SP1 does have x64 compiler (maybe its only cross-compiler, but it works) and you don’t have to install Windows SDK on your own, it is already included in installation.
And if you don’t like comments about your incapability to develop programs using WinAPI don’t write public posts with comments enabled.
I agree most of your article, but Is not new for anyone that linux *is* the perfect system to software development, it’s distribution package manager, along with a transparent environment, lack of EULAs in the most cases, and portability across different systems (including windows) is a god-send. What I’m not agree is that you must run windows variants inside your environment, since there are better solutions to that problem, such as virtualization, and remote testing, for instance.
But It was good to see that even C++ (which is supposed to be not that portable) development could be approached that easily. No comments then about Java, or .NET.
My best throughts.
Also, forgot to talk about the IDE question. Most of the time when I use dynamic languages I stick to emacs. But when developing in Java I use eclipse, and eclipse is more than visual studio team system, so you got it for free. When you compare then, you have to be aware that there’s one stuff where eclipse owns, it’s a platform for building IDEs and plugins. Visual Studio will never do that. There are so many open source plugins and open source tool integrations there (msbuild puafff check ant/maven2, ex.). Basically in eclipse you could do (or most of time, find someone who has already) much everything you need, and everything you’d want. That’s it’s better feature, it’s transparent, it’s powerful, it’s easily-extended, and it rocks! What you can get from free with VSExpress? almost nothing, emacs has more features than that (no kidding), think about SCM support for instance.
There’s no way I’m coming back to VS, there is so much to lose.
Excellent post and I too will be looking forward to reading your next article! I too have seen the light and it has nothing to do directly with Windows, never ever again. Thanks to Linux I have a stable environment from which to develop and the open source tools will let you port back to Windows.
I agree with the other poster about .NET and make sure that my code does NOT depend on anything Windows or Internet Explorer specifically. Been down that dead end road before, never again. I would add that .NET, as a platform, was designed as yet another vendor lock-in tool, there is not anything you can do with .NET that you can not do with Linux (and I do not use Mono either, why encourage vendor lock-in, if you start counting on Mono, they will just change something to break it yet another vain attempt to force people to switch to the Windows platform and Microsoft development tools. Been down that road also, never again.). Same with Silverlight, when you look at the codecs it is using there is no improvement in Silverlight that you did not have with any H.264 based codec. Here it is years later and they still refuse to allow compatibly open source codecs in a vain attempt to force their environment on users. We now know that Silverlight was a step in the wrong direction. Sadly some companies went there, I just find my content elsewhere. This is also why I do not bother with moonlight, it does not buy me anything except more artifacts, poorer resolution and inferior method because it extends the inferior Silverlight into non-Windows environments. Why use software compression to attempt to create high definition from 20fps, using software to emulate 30fps; especially when H.264 lets you create high definition natively from 30fps or higher. The fact that the video content has less artifacts, better resolution and compresses to use less bandwidth in the coming age of bandwidth caps is not lost on me either. H.264 just works and does it better. They could be compatible but they chose/choose not to be in order to lock you in to their more expensive platform.
I especially noted that. with Linux, your application’s speed was improved 5 – 10X over the Windows solution on the same hardware. While I was not surprised, I know this will be a big eye opener for others, especially hardcore Windows fanatics. And as you stated, you are/were no hater of Microsoft, you just wanted your tools to work. (Sounds so familiar) That pretty much says it all. As you know this is a common problem where Vendor-lock-in is concerned and on the Windows platform this begins at the BIOS level. (My next PC will have only Coreboot (open BIOS) capable hardware components ONLY.)
The latest .NET FUD I have read is that the .NET version (w/ memory caching built in ~ shhh your not suppose to know that) is faster than anything Linux (and they did not include memory caching ~ again shhh you not suppose to know that either); talk about a Duh moment. I guessed that is what they were doing before someone else exposed the truth of the matter. Will they never learn.
Your mention of the latest Windows platforms swapping memory out excessively is also nothing new. Another thing to love about Linux, the operating system requires less memory, so the equivalent system with more memory only means apps on Linux run more efficiently and of course faster. With Windows, they can tweak it to get closer to Linux type performance, but it will never be significantly better by design if it can ever even be better at all. So far every test where something has been better, the test has been rigged to get those results.
.
I too have been impressed with the QT toolkit and other frameworks derived from it. Thanks to Linux the future looks bright!
As to the person that was handed yet another .NET project, you are working for the wrong company, just saying. Lately if a company is 100% Microsoft I just say No and look for a better place to work. They have already drank the koolaid and I have no wish to live in Jonestown. Besides instead of the majority of the IT budget going for Licensing I would like to have a chance to earn a raise for my hard work. I bet you could successfully invest in the stock market based on the business decisions related to IT and the TCO (Total Cost of Ownership) of their IT infrastructure, but I digress.
The best companies are supporting all three environments, Linux (and Unix); Macintosh and Windows.
Remember if you do not have at least three options, you have no choice.
A great article that I am sure will be a huge eye opener for many. I am so looking forward to more based on real world experience.
For the old Pascal/Delphi hacks, have a look at the cross platform Lazarus. http://www.lazarus.freepascal.org/
@Jaroslav Šmíd
“Censorship”: I removed your first comment, as it was inflammatory and insulting. If you’re happy with coding against the WinAPI, feel free to do so, but don’t assume that other people are bad developers because they care about portability. Read for instance lamapper excellent comment.
Regarding x64 and VS 2008 Express — I cannot find reliable information where this is stated. As I don’t use it, I trust MSDN and a quick websearch, and these tell me that I have to install the Platform SDK to compile native x64 applications. But guess what, my XP at work is 32bit only, so I couldn’t have run them anyway.
Regarding WinAPI development: It’s not always that easy to stick with WinAPI, as it lacks for instance OpenEXR support in WIC, doesn’t it? Sometimes, especially in research, you must rely on libraries as the functionality is specific to your domain, and there is simple no way to rewrite it quickly.
>I bet you could successfully invest in the stock market based on the business decisions related to IT and the TCO (Total Cost of Ownership) of their IT infrastructure….
This occurred to me, too! A sort of “IT arbitrage”!
I am not a developer, but became disgusted with Windows about seven years ago and began investigating Linux. Today I use OpenSolaris which, from my point of view, makes everything else seem like chewing gum and bailing wire. I know someone who is a contract writer for a large international corporation and works remotely, have witnessed her forced to phaff-around with Vista and the other various Microsoft “tools”, and couldn’t help but be amazed. I found myself wondering, “Gee, is there another company of comparable capitalization in direct competition that uses intelligent IT platform/tools?” One could look for a bump in the stock price of the former company coinciding with a dip in the latter, buy the spread, wait for the inevitable crossover, and cash in. IT arbitrage — a new concept in speculation!
@Anteru
> I cannot find reliable information
Well, I don’t know if it was included in MSVC EE 2008, but it is included in MSVC EE 2008 SP1 as I was able to compile x64 application without installing Windows SDK (it really was x64 application, because there was no “star” in task manager).
> But guess what, my XP at work is 32bit only, so I couldn’t have run them anyway.
Not true, again. Cross compiler from 32bit to 64bit is also available.
But it makes no sense to post here anymore, my comment will be censored again
@Jaroslav Šmíd
Err, you seem to miss the problem with x64: Even it it comes with a cross-compiler, I still only have x86 Windows available, so I cannot run x64 code and benefit from the (hopefully) improved performance.
As I said, I don’t know what’s the case for the Express Editions, but if you have a link somewhere, I’d be happy to add it. Right now, my understanding is that “stock” Express Editions require installing the Windows SDK to get a x64 compiler.
Feel free to comment, just keep it cool and friendly as all the others did!
Pingback: Links 16/09/2009: New Unbreakable, Berkeley DB | Boycott Novell
Pingback: Destillat KW38-2009 | duetsch.info - GNU/Linux, Open Source, Softwareentwicklung, Selbstmanagement, Vim ...
I have been developing on .NET since 2003. I currently run XP with VS2008. I have also been developing on unix/linux since 1993 on just about every flavor ‘nix I can think of. I am currently running Netbeans 6.7.1 on SuSE 11.1
Comparing the two platforms is simply a matter of money. If you have a mission critical app that absolutely must be done to very short deadlines, you really do not want to do it on linux. VisualStudio has far, far better RAD support for almost every eventuality. However, if time is not a constraint, but performance and licencing issues are, then go with linux. If your time is cheap go linux. If your time is expensive (i.e if someone else is paying!) go VisualStudio. It’s that simple.
sorry man ,,,,,,but i am going to copy your whole article to post in my site.
:p ..nice article ..mst say
Pingback: Flow » Blog Archive » Daily Digest for September 20th - The zeitgeist daily
Pingback: Alexandru Bolboaca-Diaconu (alexboly) 's status on Sunday, 20-Sep-09 09:37:57 UTC - Identi.ca
Uhm… Wrong! Wrong! Wrong!I dont know how to it on Windows but rc.local always does its work lol. It doesnt screw up configuration, it doesnt do anything wrong lol!Rc.local is the last thing executed before you enter a desktop environment so it parses new configuration and it remains that way.Have you actually tried linux or just read something over internet about that? Lets not even talk how pointless your example was.Changing IP adress at boot? WTF? You could simply use network settings on windows and change the IP adress and guess what? After reboot its still the same… What a discovery! You dont need to that every time… We clearly see the superior OS…On linux you just change the configuration file (oh, noes). And even if you dont know what configuration file to use rc.local will always do. And since most probably youd be using one of the graphics distros, theres no need of manual file editing…Jeez..
While I’m not really in the same vein of developer – I’m a sysadmin and most of the development that I do is PHP – I really enjoyed reading your post. I think it seems like a lot of people are just religious about Microsoft – that it’s the Right way to do things and everything else is Wrong. While personally (I’m a Linux admin, what can I say) I only run linux on my desktops and laptop, I think of it like buying a hammer and one screwdriver and trying to build a car. You have to choose the right tool for the job, and it’s just myopic to think that the one “most popular” tool is the best in all cases.
I know that a lot of proprietary software developers are “locked in” to a non-portable language like .NET (or even C/C++, as it requires recompiling). But as to Linux, it would be so much nicer for us Linux users (or even Mac users) if more shops started developing in Java or Python or something else that’s actually portable across OSes without recompiling.
Also, just to throw this in, I work for a major university (our IT department supports 50,000+ users) and in the data center, we’re almost 100% Linux. We’ve even given up our Solaris support contract. I don’t know what advances have been made in Windows 2008 (I know they promised a lot) but for mission-critical server applications, Windows just doesn’t seem to have the reliability and uptime, you have to restart to perform major updates, and it’s a real pain to administer compared to Linux.
Pingback: Demuxer blogspot.com (demuxer) 's status on Wednesday, 23-Sep-09 18:56:55 UTC - Identi.ca
Thanks for the info!
Pingback: Open News | Pāreja uz Linux: Windows vides programmētāja viedoklis
@Bill
Yeah, but the reason he could not compile on Windows easily was due to the third-party library which he would not only have to recompile but all of its dependencies too. Since the source code is available for a lot of libraries on Linux and not so much on Windows, I think that is the reason he chose Linux. Not due to the lack of good IDEs on Windows.
Troll much?
why are you using an ubuntu based distro to compare speed? you should be using a less bloated distro such as arch gentoo or slack
Simply because I wanted to get running _quickly_ — installing Wubi took ~20 minutes, and Ubuntu is also well supported by most apps (for instance, there are installers for CUDA etc.)