PHP versus ASP.NET – Windows versus Linux
How does IMPLEMENTATION Performance Compare ?
Usually, when someone creates benchmarks, they are trying to prove that their thing is faster than someone else's thing.
I’m PAID by Microsoft to write BOTH PHP and ASP.NET Code. I was doing PHP before .NET shipped. I love them both.
This makes it hard for me to say anything good about either one. When I confer a preference for something in PHP, my Microsoft peers send me flame mail and when I confer a preference for something in ASP.NET, my PHP friends come out of the woodwork to call me a Microsoft shill.
I started building and running these tests because everyone had opinions about comparative PHP performance (Windows versus Linux & 5.2 versus 5.3), but no one had any solid data.
So, I decided to collect some empirical evidence of my own.
Before you look at them, let m e provide some method details and context.
All tests were run on the SAME Machine.
A Toshiba Tecra M5 with 4 Gig of ram and a 60 Gig 7200 RPM Hard Drive.
Ubuntu 9 and Windows Server 2008 Standard were natively installed on 2 separate (but identical) hard drives.
The web servers were Apache2 on Linux and IIS 7 on Windows.
Both operating systems were fully patched / updated.
No Operating System or Development Runtime performance enhancements were added.
I wasn’t investigating how much speed an expert could custom tailor the tests to on a specific platform.
Yes, I could implement PHP Byte Caching, or for ASP.NET I could use Page Caching, Partial Page Caching, SQL Cache Dependency, Multi Threading, etc.
Both Windows and Linux Implementations of PHP will benefit from PHP Byte Code caching.
My goal was to determine the relative speed of THE IMPLEMENTATION.
I found the results both interesting and unexpected.
PHP on Linux Versus PHP on Windows…..
I really though one would just be faster than the other, but I was wrong. Some things are faster on Windows, other are faster on Linux.
- RAW statement execution seems faster on Windows.
- Function Calls were faster on Windows
- Object Creation / Access was faster on Linux with PHP 5.2 but faster on Windows with 5.3
- Library calls were faster on Linux. (Example: Encryption 3-5 times faster on Ubuntu.)
- File Access is faster on Linux by a small percentage, except for file copy operations which was as much as 60% slower on Windows probably due to the ACL advanced security.
- MySQL access with Linux is faster by more than a little and on Windows, MySQL access deteriorates in version 5.3 (This seems to be poor implementation, see PostgreSQL below.)
- PostgreSQL performance is very close on both platforms (within 6/100 of a second for 1000 Operations) – It’s faster on Windows and faster still on Windows with PHP 5.3
- MS SQL Server access from PHP 5.2 on Windows is marginally slower than MySQL access on Linux. (PHP 5.3 not yet supported at the time of this writing.)
So what does all that mean ?
- We can probably say that in terms of raw execution – performance on Linux versus Windows is probably a wash (more or less equivalent) so that the performance of PHP itself becomes a moot factor in choosing Linux or Windows for PHP application deployment.
- If you are building an application, or running an application that supports it, PostgreSQL might be a better database choice since it performs pretty much the same on Windows and Linux.
- If you are running an application that locks you in to Sun Microsystems’ MySQL and you want to run it on Windows, your should do scale planning. (My personal guess is that it’s unlikely that Sun will markedly improve MySQL performance on Windows. )
- Version 1 of the PHP Driver for SQL Server (V2 is in the works) is somewhat slower than MySQL or PostpreSQL but probably not enough to discourage use where diverse developer access is desired. (v2 ot the driver will improve performance. )
By and large I think the PHP team and the Microsoft IIS team have accomplished good raw performance equivalence across platforms. (Now we just need to get the Open Source Application teams (Drupal, WordPress, Joomle, etc.) to do performance optimization on both !)
PHP versus ASP.NET Raw Performance …..
By now you have cheated and looked at the spread sheet.
Yes, ASP.NET is universally faster than PHP (on Windows and on Linux) with the exceptions of File Copy and Attribute operations.
MySQL Access from PHP on Linux is a TINY bit faster than SQL Server access on Windows (assuming common data types and SELECT statements) but probably not enough to matter.
ASP.NET (C#) operations, object use, library calls, etc. are SIGNIFICANTLY faster that the PHP equivalents.
I know my PHP friends and the Linux dudes (and dude-etts) will probably come out of the wood work to refute my tests and results :)
I’ve always thought that if high end performance options were part of your needs requirements, then .NET programming has some advanced options “out of the box” like multi-threading, asynchronous requests, and a number of caching options.
NOTE – I’m not saying “ASP.NET is Faster so you shouldn't choose PHP !!!! I’ve always contended that the affable simplicity of PHP had some drawbacks for certain advanced applications. (Just as the early learning complexity of ASP.NET can have it’s drawbacks. )
To me (your mileage may vary) the exciting thing about PHP is not the language / platform so much as it is what thousands of clever PHP Developers have done with it (Drupal, Joomla, Wordpress, PHPBB, Nuke, etc.)
In any event, it’s nice to now have some data that PHP performance on Windows and Linux are “in the same ballpark”.
Now I can start writing those Windows specific PHP libraries I’ve been dreaming about for years !!
Posted in: General asp.net | Tags: asp.net php windows linux implementation performance compare windows versus linux sql server postgresql ms sql server mysqlCOMMENT WARNING
- I know some will be incensed by these tests. You are welcome to comment and disagree, but if you can't be polite I’ll simply delete your comments and block your IP address.
- If you dislike the results and want to refute them – DO THE WORK. Accompany your dissent with DATA. Take my code or write your own and argue with FACTS.
Common Questions and Answers from Performance Tuning Webinars
Q: Which will be faster out of these two queries?
SELECT ... WHERE some_col IN (1,2,3) or
SELECT ... WHERE some_col = 1 OR some_col = 2 OR some_col = 3
A:
Neither. The optimizer rewrites an IN() operator to a series of OR conditions, so there will be no performance diffference. Use IN() as it makes the code shorter and more readable.
Q: Where does MyISAM cache table records?
A:
Nowhere. MyISAM does not cache table records like InnoDB does in it's innodb_buffer_pool. Instead, MyISAM relies on the operating system buffering to buffer table records as it reads them from the .MYD file. The MyISAM key_buffer only stores index blocks, not data records.
Q: Which will be faster out these two queries:
SELECT ... FROM t1, t2 WHERE t1.id = t2.id
SELECT ... FROM t1 INNER JOIN t2 ON t1.id = t2.id
A:
Neither. The optimizer actually will rewrite the bottom query into the top form. The SQL style you use is, of course, entirely up to you, however I recommend using the bottom style (known as ANSI syntax) over the top style (known as Theta syntax) for a couple reasons:
- MySQL only supports the inner and cross join for the Theta syntax. However, MySQL supports INNER, CROSS, LEFT and RIGHT outer joins for the ANSI syntax. Mixing and matching both styles can lead to hard-to-read SQL code.
- It is supremely easy to miss a join condition with Theta style, especially when joining many tables together. Leaving off a join condition by accident in the WHERE clause will lead to a cartesian product (not a good thing!). ANSI syntax is more explicit, and it is much harder to forget a join condition
Q: Is InnoDB faster/better than MyISAM
A:
It completely depends. Nobody ever really likes the answer to this question, but it is completely true. There are strengths and disadvantages to each storage engine. MyISAM has very good read performance, bulk load performance, and has a small footprint. But, InnoDB is great for heavy UPDATE environments, transaction needs, referential integrity, and fast single key lookups. You need to pick an engine based on what your application needs, and not some general "only use XXX engine" dictate.
Q: Is CHAR faster than VARCHAR?
A:
No, not really. If there is any performance difference, it is negligible. Pick CHAR if you know that the data has a specific number of characters (like a social security number, for instance) and VARCHAR otherwise.
Q: Is VARCHAR(80) faster than VARCHAR(255)
A:
Yes, but probably not in the way you think. AFAIK, there's no difference (at least in recent versions of MySQL and InnoDB) between the speed at which VARCHAR columns of different lengths are retrieved from disk or memory. However, there is a big difference when either of the following scenarios occurs:
- A temporary table is implicitly created to handle a GROUP BY or ORDER BY clause and a VARCHAR column is in the SELECT statement
- A temporary table is created explicitly which contains a VARCHAR column
In these cases, the length of the VARCHAR columns does come into play. Why? Because temporary tables in memory are actually just tables of the MEMORY storage engine. The MEMORY storage engine, for some reason, treats all VARCHAR(X) columns as CHAR(X) columns.
This means that if you define two fields, one as VARCHAR(255) and another as VARCHAR(128), the latter will consume half as much space when allocated in a temporary table. The more records can fit into the max_heap_table_size, the fewer cases of swapping to disk tables (look for SHOW STATUS LIKE 'Created_tmp_disk_';) will occur, resulting in better overall performance.
Q: Are there performance issues when joining tables from different storage engines
A:
No. Issuing a SELECT against multiple storage engines is fine. It's when you mix and match transactional and non-transactional engines within a transaction that modifies data that you will get unpredictable results.
Q: If I change a derived table to a view, will performance increase?
A:
No. A view is simply a derived table behind the scenes (at least when created using the TEMPTABLE algorithm). This means there is no performance difference between a regular derived table and a view. The view will simply make the code more readable and more "componentized".
Q: If I see "Using temporary; Using filesort" in the Extra column of EXPLAIN output, does that mean a temporary table is created on disk?
A:
No. A disk-based table will only occur in the following situations:
- When the size of the implicitly created temporary table (from a GROUP BY or ORDER BY on a non-indexed column) is greater than both tmp_table_size and max_heap_table_size
- When there are any BLOB or TEXT fields in the SELECT expression
- When a full table scan occurs that exceeds the read_buffer_size variable (configured per connection thread)
These are the scenarios (off the top of my head) I can think of which cause disk-based temporary table creation. There could be a few more. By the way, the disk-based temporary table created is a MyISAM table.
Q: Is it possible to do a FULL OUTER JOIN in MySQL?
A:
Yes. Use both LEFT and RIGHT JOIN on the same join condition in the same query, like so:
SELECT * FROM A LEFT JOIN B ON A.id = B.id UNION ALL SELECT * FROM A RIGHT JOIN B ON A.id = B.id WHERE A.id IS NULLPosted in: Interview Questions database | Tags: interview questions and answers interview performance mysql database sql pl sql tuning webinars full outer join outer join using
Best blog system – WordPress, using php and mysql
WordPress started in 2003 with a single bit of code to enhance the typography of everyday writing and with fewer users than you can count on your fingers and toes. Since then it has grown to be the largest self-hosted blogging tool in the world, used on millions of sites and seen by tens of millions of people every day.
Everything you see here, from the documentation to the code itself, was created by and for the community. WordPress is an Open Source project, which means there are hundreds of people all over the world working on it. (More than most commercial platforms.) It also means you are free to use it for anything from your cat’s home page to a Fortune 500 web site without paying anyone a license fee and a number of other important freedoms.
About WordPress.org
On this site you can download and install a software script called WordPress. To do this you need a web host who meets the minimum requirements and a little time. WordPress is completely customizable and can be used for almost anything. There is also a service called WordPress.com which lets you get started with a new and free WordPress-based blog in seconds, but varies in several ways and is less flexible than the WordPress you download and install yourself.
A Little History
WordPress was born out of a desire for an elegant, well-architectured personal publishing system built on PHP and MySQL and licensed under the GPL. It is the official successor of b2/cafelog. WordPress is fresh software, but its roots and development go back to 2001. It is a mature and stable product. We hope by focusing on user experience and web standards we can create a tool different from anything else out there.
2005 was a very exciting year for WordPress, as it saw the release of our 1.5 version (introduced themes) which was downloaded over 900,000 times, the start of hosted service WordPress.com to expand WP's reach, the founding of Automattic by several core members of the WP team, and finally the release of version 2.0.
After 1.5 we seemed to have something people really liked and we've experienced some fairly rapid growth. Here are some metrics for 2006 and 2007.
In 2006 we had 1,545,703 downloads, in 2007 we had 3,816,965!
As for plugins we had 191,567 downloads of 371 unique plugins in 2006. In 2007 there were 2,845,884 downloads (15x growth) of 1,384 plugins.
2006 saw the introduction of the first WordCamp in San Francisco.
In 2007 we adopted a regular release schedule, putting out major feature releases roughly every 3-4 months, or three times a year.
Because of the number of improvements in version 2.5 we took an extra 3 months on it, but 2008 looks on track to do three major releases again. It will be a very exciting year.
There are now dozens of WordCamps around the world, from Vancouver to Dallas to Milan, Italy.
To run WordPress your host just needs a couple of things:
* PHP version 4.3 or greater
* MySQL version 4.0 or greater
That's really it. We recommend Apache or Litespeed as the most robust and featureful server for running WordPress, but any server that supports PHP and MySQL will do. That said, we can’t test every possible environment and each of the hosts on our hosting page supports the above and more with no problems.
Key Features
* Full standards compliance — We have gone to great lengths to make sure every bit of WordPress generated code is in full compliance with the standards of the W3C. This is important not only for interoperability with today's browser but also for forward compatibility with the tools of the next generation. Your web site is a beautiful thing, and you should demand nothing less.
* No rebuilding — Changes you make to your templates or entries are reflected immediately on your site, with no need for regenerating static pages.
* WordPress Pages — Pages allow you to manage non-blog content easily, so for example you could have a static "About" page that you manage through WordPress. For an idea of how powerful this is, the entire WordPress.org site could be run off WordPress alone. (We don't for technical mirroring reasons.)
* WordPress Links -- Links allows you to create, maintain, and update any number of blogrolls through your administration interface. This is much faster than calling an external blogroll manager.
* WordPress Themes — WordPress comes with a full theme system which makes designing everything from the simplest blog to the most complicated webzine a piece of cake, and you can even have multiple themes with totally different looks that you switch with a single click. Have a new design every day.
* Cross-blog communication tools— WordPress fully supports both the Trackback and Pingback standards, and we are committed to supporting future standards as they develop.
* Comments — Visitors to your site can leave comments on individual entries, and through Trackback or Pingback can comment on their own site. You can enable or disable comments on a per-post basis.
* Spam protection — Out of the box WordPress comes with very robust tools such as an integrated blacklist and open proxy checker to manage and eliminate comment spam on your blog, and there is also a rich array of plugins that can take this functionality a step further.
* Full user registration — WordPress has a built-in user registration system that (if you choose) can allow people to register and maintain profiles and leave authenticated comments on your blog. You can optionally close comments for non-registered users. There are also plugins that hide posts from lower level users.
* Password Protected Posts — You can give passwords to individual posts to hide them from the public. You can also have private posts which are viewable only by their author.
* Easy installation and upgrades — Installing WordPress and upgrading from previous versions and other software is a piece of cake. Try it and you'll wonder why all web software isn't this easy.
* Easy Importing — We currently have importers for Movable Type, Textpattern, Greymatter, Blogger, and b2. Work on importers for Nucleus and pMachine are under way.
* XML-RPC interface — WordPress currently supports an extended version of the Blogger API, MetaWeblog API, and finally the MovableType API. You can even use clients designed for other platforms like Zempt.
* Workflow — You can have types of users that can only post drafts, not publish to the front page.
* Typographical niceties — WordPress uses the Texturize engine to intelligently convert plain ASCII into typographically correct XHTML entities. This includes quotes, apostrophes, ellipses, em and en dashes, multiplication symbols, and ampersands. For information about the proper use of such entities see Peter Sheerin's article The Trouble With Em ’n En.
* Intelligent text formatting — If you've dealt with systems that convert new lines to line breaks before you know why they have a bad name: if you have any sort of HTML they butcher it by putting tags after every new line indiscriminately, breaking your formatting and validation. Our function for this intelligently avoids places where you already have breaks and block-level HTML tags, so you can leave it on without worrying about it breaking your code.
* Multiple authors — WordPress' highly advanced user system allows up to 10 levels of users, with different levels having different (and configurable) privileges with regard to publishing, editing, options, and other users.
* Bookmarklets — Cross-browser bookmarklets make it easy to publish to your blog or add links to your blogroll with a minimum of effort.
* Ping away — WordPress supports pinging Ping-O-Matic, which means maximum exposure for your blog to search engines.