www.ngonchan.blogspot.com:

Innodb or MyISAM? What's your preference?



Here is the discussion about the difference between InnoDB and MyISAM MySQL engine.
The original discusstion is in MySQLDatabaseAdministration
This discussion answer so many question for me :)
Thanks the authors in this discussion :)

And,  at the last, we should read from begin to the end of the discussion for the best :P

by Frank

I have been reading a lot about Innodb and MyISAM recently. MyISAM offers speed whereas Innodb offers reliability. MyISAM is fast but with no transactions support, Innodb has certain, but very important limitations.

I hate to ask it like this, but what do you prefer for a high volume application with heavy inserts/updates/selects? In your regular job (and projects), do you go for the speed or the reliability? or do you try to find a balance between both by having tables of both kinds?

I am just interested in hearing your thoughts (and igniting a discussion) as to which one is better in the long run?

I have personally used MyISAM and outsourced everything else to my application so far.

Thanks

At 1:23 AM, Blogger Markus Popp said...
If there are many modifications of the data, it's said that InnoDB works faster because it uses row locking instead of table locking, like MyISAM. However, if there are mainly SELECT statements, a MyISAM table might be faster.

However, it's always important what the needs of a specific table are - so I would choose the storage engine that best fits the requirements for the given table. If you need foreign key constraints or transactions, you can only use InnoDB, wheras if you need fulltext indexes, you can only use MyISAM tables at the moment.

With replication it's even possible to take advantage of both storage engines on one table. For example, the master could store a table as InnoDB which makes it fast for INSERTs, UPDATEs and DELETEs while the slave(s) could store the same table as MyISAM and offer the best performance for SELECTs.

At 1:58 AM, Blogger Michael Metz said...
If you have a lot of cncurrent inserts/updates I would recommend inndb since it supports row-locking.
I'm managing a community with more than 5.000 qps Peak (on one DB-Server) and it runs smoothly with innodb while myisam was unable to process the high percentage of inserts/updates (about 50%).



At 2:27 AM, Blogger Frankly Speaking! said...
Thanks Michael,

You are right, for concurrent inserts and updates, one should go for data integrity rather than speed.

Markus, I really appreciate your tip on getting the benefit of both worlds using replication.

Frank

At 9:43 AM, Blogger Markus Popp said...
Unfortunately there's a little uncertainty about the long-term future of InnoDB inside MySQL since Oracle bought Innobase and with it the InnoDB storage engine.

However, I don't think that there will be problems in the short- and mid-terms, and until there *could* be some problems, MySQL should have time enough to create its own storage engine(s) that support everything that InnoDB can do (the plugable architecture should provide good help). At least I think that MySQL should try to keep its independency by providing everything that a high level RDBMS needs by themselves.

At 12:35 PM, Blogger Sheeri said...
What Markus said!

We have lots of different data and usage -- sessions and users tables that get updated frequently, and static data like postal codes.

We currently have a mix -- there's even one set of data (personal ads) that we have 2 tables for -- One table is a copy of the other, and the difference is one is innoDB for fast inserting, and the other is MyISAM for fulltext searching.

InnoDB for most of the tables, including the messaging (short e-mails back and forth) because we need the row-level locking (memory page level locking, really. That's important when you have so many updates per second like we do.)

MyISAM (packed, preferably) for static data -- UK zip code info is over 120M unpacked, and it never changes (and if it does, we just replace the table).

So, yeah, what markus said.

At 2:44 PM, Blogger Frankly Speaking! said...
Thanks Sheeri,

Like Markus and you pointed out, a replication with a dual setup will give the best of both worlds.

Seeing that Innodb is now in Oracle's hands, I think MySQL should start immediately on making the way to get independent from Innodb.

Now I will have to look into the plugable architecture :)

Frank

At 11:50 AM, Anonymous Anonymous said...
I'd go with InnoDB until it's been proved that it's unsuitable. The first reason is reliability. Get a crash with MyISAM and you have the unreliable and slow, related to table size, table repair process. Same thing with InnoDB and you instead get the fixed time, fast and reliable log apply/rollback process. As the data set gets bigger, this matters more and more, as it does if you want to do things like sleep instead of being woken up in the middle of the night to fix a crashed table.

For reliability and performance, we use InnoDB for almost everything at Wikipedia - we just can't afford the downtime implied by MyISAM use and check table for 400GB of data when we get a crash.

The speed advantage of MyISAM is overstated IMO. LiveJournal with a mostly write environment saw a big increase in speed when it switched from MyISAM to InnoDB and they are very happy with InnoDB.

At Wikipedia we achieved some major performance gains by exploiting the way InnoDB clusters records by their primary key. Took some quite common queries from 50 seeks per result page to 1 or 2 seeks per page. Worse, the code at that time allowed people to go back 50,000 rows using LIMIT, causing 50,000 seeks and a DOS vulnerability. Big improvement to working set size from the change as well, so the results were more often in cache. It's so great an advantage that like the write caching it could be a dealbreaker for anything MySQL might do about alternatives to InnoDB.

With InnoDB, if you don't need repeatability, you might also switch to the least consistent transaction isolation level for a particular query, since that can reduce the locking work InnoDB needs to do. That is, assuming that you really do need only the MyISAM lack of guarantees.

On the other hand, a crazy bit of code did once use SELECT ... FOR UPDATE to scan every row of a table. Switching that table to MyISAM was a quick hack until it could be fixed. The table locking of MyISAM was way faster than watching InnoDB lock every row individually.

We used to use MyISAM for fulltext, duplicating the data in the InnoDB master table. Once the query rate grew sufficiently high and the data size grew past a gigabyte or so it became completely unacceptable on performance grounds, taking more than half of our database server capacity and still not working well. We abandoned it and switched to Lucene. By that point we were in the top thousand sites on the net, so it had survived pretty well.

I'm also as MySQL Support Engineer but these views are from my Wikipedia role, not the MySQL one.

James Day

At 5:22 PM, Anonymous Anonymous said...
Newbies use MyISAM for their website because "it's faster".

When you're on your test server and the only user online, sure...

And then people come and sign up and it starts to lock all around the place.

At 7:55 PM, Anonymous Anonymous said...
Given my experience with BOTH innodb and myisam, I'd go with Oracle. Best storage engine under the hood. Cheers!

At 8:50 PM, Blogger Reza said...
Hi Frank,
You have raised an interesting discussion.
I develope large scale applications and I a mix of InnoDB and MyISAM.
My applications always read everything from database, even the copyrights. I use MyISAM for such a thing as the SELECT query is much faster. InnoDB works great when I use it for data such as employees information and so on.
The fact that Michael mentioned to use InnoDB in master and MyISAM in slave is great.
For example, replicate two servers and call both primary DB Servers.
Redirect all requests to a server called Data Handler, and depending on the current usage and traffic, simply redirect the request to one. you could also use priority in the algorithm of redirection.

Cheers,
Rex

At 8:42 PM, Anonymous Richard said...
I have a joining table (with some additional data) that has two foreign keys.

I've recently changed it from using a surrogate key and indexes on each of the foreign key fields, to using a compound primary key on the foreign key fields and deleting the surrogate key.

My concern is having read the comments above, my users are only really seeing the results of select queries. Almost all the inserts and updates are happening behind the scenes via crontab etc.

There's over 3 million rows now and I'm struggling to get the table to convert from MyISAM to InnoDB. I'd like to see if it runs better. Since getting rid of the surrogate key and indexes the front end of the site seems a little slower which is obviously not ideal. :(

At 2:42 PM, Anonymous Anonymous said...
Hi,
i have a DB with aout 50G.
I use mix storage Myisam and InnoDb.
We have something like 500k Updates,500k selects and 100k Insert/delete/replace per hour.
Many full scan becouse of update and
i must say InnOdb it doesnt really work. for the update MyISAM takes 6 minutes innodB needs a couples of hours.
Maybe my installation of INnoDB is not fit

At 4:01 AM, Blogger Jayant Kumar said...
hi, i have been trying to use innodb. Have converted a huge db of around 14 GB from myisam to innodb and put the required index. But the machine (6 GB RAM & 2X2 CPU ) machine is unable to handle the incoming requests. I have hight QPS

Myisam used to work fine.

I have set the innodb_buffer_pool to 2 GB and innodb_thread_concurrency to 8.

Please let me know if there is anything else that i need to do to increase performance.

At 1:42 AM, Anonymous France Hsu said...
Hi!
I want to save logs in DB.
Usually, I use INSERTs and SELECTs, and only DELETEs for the overdue logs. I needed to retain recently 6 month-long logs
In this case, which DB engine is suitable for me?

At 1:43 AM, Anonymous France Hsu said...
Hi!
I want to save logs in DB.
Usually, I use INSERTs and SELECTs, and only DELETEs for the overdue logs. I needed to retain recently 6 month-long logs
In this case, which DB engine is suitable for me?
Thanks.

At 1:48 AM, Anonymous France Hsu said...
Hi!
I want to save logs in DB.
Usually, I use INSERTs and SELECTs, and only DELETEs for the overdue logs. I needed to retain recently 6 month-long logs
In this case, which DB engine is suitable for me?
Thanks.

At 5:20 PM, Anonymous Roebie said...
Having worked with myIsam, InnoDB and Oracle, I would advise PostgreSQL. I've got some tables with >500,000,000 records and >90 fields each. PostgreSQL easily beats Oracle on speed (both select and insert/update) and we have never had any reliability issue since we started with PostgreSQL 3 years ago.
Oh, by the way, even when joining a PostgreSQL table with an Oracle table in our PostgreSQL database, performance is great. Just try that the other way round...

At 9:33 PM, Blogger Emerson said...
Hi!
I used MyISAM for more than 2G row instead of InnoDB. How can we maximize the table row in InnoDB?
-emer

At 7:19 AM, Anonymous Ketan Thaker said...
Thank you all!

I am using both MyISAM and InnoDB database engine in my application as I am using full-text index on product master table and InnoDB for order master table as it is being used by as desktop application running on local server to download orders data from online server to local MySQL server.

Since am dealing with a Database of 2GB in size haven't feel speed issue yet because of proper indexing on the fields.

Thanks,

PS: please advice if I have to update further.

At 4:27 AM, Anonymous Anonymous said...
Hi,

this Blog is very interesting. I have a application running on InnoDB tables. I need transactions only on a few tables, which contains few rows. I use big tables only for reading and I have to make a full load to fill the tables. (The data comes from a flat file)
My problem is that the load needs a lot of time and also to empty the table.
The performance of the application is O.K. but could be better. Is there any difference between InnoDB and MyISAM for the load table? Regards Joern

At 11:47 AM, Anonymous Anonymous said...
I added some of the stuff i learned from this page on the sysadmin wiki if you don't mind:
http://sysadmin.wikia.com/wiki/MySQL


Read More Add your Comment 22 nhận xét


A song for a stormy night - Secret Garden



Mấy bữa nay mưa nhiều, trời mưa nằm nghe bài hát này, hay lạ kì :( Dạo này lại khoái nghe Secret Garden, lạ nhỉ :D



*



The rain beats hard at my window,

While you, so softly do sleep;

And you can't hear

the cold wind blow,

You are sleeping so deep



Outside it's dark,

the moon hiding,

By starlight only I see,

The host of the night-time go riding,

But you are safe here with me.



So, while the world out there

is sleeping,

And everyone wrapped up so tight,

Oh, I am a vigil here keeping,

On this stormy night;



I promised I always would love you,

If skies would be grey or be blue,

I whisper this prayer now above you,

That there will always be you.



Sometimes, we're just like the weather,

Changing by day after day

As long as we'll be together,

Storms will pass away.



I said I would guard and protect you.

Keep you free from all harm;

And if life should ever reject you,

That love would weather each storm.



So, while the world out there

is sleeping,

And everyone wrapped up so tight,

Oh, I am a vigil here keeping,

On this stormy night;



I promised I always would love you,

If skies would be grey or be blue,

I whisper this prayer now above you,

That there will always be you.



(Secret Garden's Wonderful Violin)



Soon, I know you'll be waking,

Ask did I sleep - did I write?

And I'll just say I was making...

A song...

for a stormy night.


Read More Add your Comment 1 nhận xét


Advanced JavaScript: Closures, Prototypes, Demystified



Original post's here


The times when JavaScript was just a toy language for making image rollovers and other, more irritating effects, are fortunately long gone. Today developers build much more sophisticated and complex applications be they for the Web (GMail), the desktop (Firefox extensions) or the server. JavaScript’s prototypal nature makes its object-oriented features really different than “classical” languages like Java and C++, and we have to make sure we use the right tool the right way. In this talk you’ll learn about JavaScript’s most commonly misunderstood features and how you could put them to a good use.





Read More Add your Comment 1 nhận xét


10 JavaScript Quick Tips and Best Practices [for beginners]



Impressive Webs've created a great tutorial for JavaScript beginners here:

Recently, a few blogs and tutorial sites have posted some really good articles on JavaScript tips and best practices, and I thought that was a good topic that could easily be expanded upon. So I put together a list of 10 fairly simple JavaScript tips and best practices of my own.

I tried to include stuff that was not mentioned in those other posts, but I’m sure there is a little bit of overlap. Keep in mind that these are brief tips and recommendations, so I don’t go into great detail about the reasons and such, but I may go into some of them in depth in future articles and tutorials.

In the meantime, please enjoy this list of tips, recommendations, and best practices for JavaScript coding.

1. Use the defer Attribute for IE-Only External Scripts


This is not necessarily a must-do, and neither is it a best practice, but it could come in handy at times. The defer attribute is declared inside of a <script> tag in XHTML like this:


  1. <script type="text/javascript" defer="defer"></script>




The purpose of defer is to tell the externally linked script to wait until the page finishes loading until it runs. The same thing can be accomplished via good unobtrusive JavaScript methods, which usually include code that prevents scripts from executing until the DOM is finished loading.

The advantage of defer occurs in connection with Internet Explorer, since that browser is the only one that supports the defer attribute. So, if you need a quick script to run only in IE, and you don’t mind if the entire page loads before it starts to execute, then simply add defer="defer" in your <script> tag and that will quickly take care of that problem. Fixing a transparent PNG issue in IE6 is one possible practical use for defer.

(Edit 8/3/09: The defer attribute must be used when hiding a script from other browsers with a conditional comment that targets an IE-only script — otherwise the script will run normally in other browsers.)

2. Use a CData Section to Prevent XHTML Strict Validation Errors


Most of the time your scripts will reside in external files, and will be called in a <script> tag either in the <head> of the document, or right before the closing </body> tag.

But there may be an instance where you’re including JavaScript right in the HTML page itself, inside of <script> tags, like this:


  1. <div>

  2. <p>

  3. <script type="text/javascript">

  4. var my_variable = 100;

  5. if (my_variable < 50) {

  6. // do something here...

  7. }

  8. </script>

  9. </p>

  10. </div>




Do you notice the “less than” symbol, which is part of the if statement? That symbol will cause the page to have validation errors, unless you wrap your code in a CData section, like this:


  1. <div>

  2. <p>

  3. <script type="text/javascript">

  4. //<![CDATA[

  5. var my_variable = 100;

  6. if (my_variable < 50) {

  7. // do something here...

  8. }

  9. //]]>

  10. </script>

  11. </p>

  12. </div>




3. Avoid JavaScript’s Keywords When Creating Custom Identifiers


Many words are reserved as keywords in JavaScript, so you should avoid using them as variable names or other custom identifiers. The complete list of JavaScript keywords is as follows:


  1. break

  2. case

  3. catch

  4. continue

  5. default

  6. delete

  7. do

  8. else

  9. finally

  10. for

  11. function

  12. if

  13. in

  14. instanceof

  15. new

  16. return

  17. switch

  18. this

  19. throw

  20. try

  21. typeof

  22. var

  23. void

  24. while

  25. with




4. Avoid JavaScript’s Reserved Words When Creating Custom Identifiers


There are also JavaScript reserved words, which are not necessarily currently used in the language, but are reserved for future use as keywords. Those words are as follows:


  1. abstract

  2. boolean

  3. byte

  4. char

  5. class

  6. const

  7. debugger

  8. double

  9. enum

  10. export

  11. extends

  12. final

  13. float

  14. goto

  15. implements

  16. import

  17. int

  18. interface

  19. long

  20. native

  21. package

  22. private

  23. protected

  24. public

  25. short

  26. static

  27. super

  28. synchronized

  29. throws

  30. transient

  31. volatile




5. Don’t Change a Variable’s Type After Initial Declaration


In JavaScript, technically, the following is perfectly legal:


  1. var my_variable = "This is a String";

  2. my_variable = 50;




After the variable’s initial declaration as a string on line 1, on line 2 its value is changed and its data type is also changed. This is not good practice and should be avoided.

6. Don’t Use Global Variables


To prevent possible conflicts, in 99% of cases, use the var keyword when initially declaring variables and their values. This ensures that your variables are localized and are not accessible outside of the function in which they are declared. So, if you happen to use the same variable name in two different functions, there won’t be a conflict since each variable will be abolished the moment its function finishes executing.

7. JavaScript is Case-Sensitive


Remember that the following two variables represent two completely different place holders:


  1. var myVariable = "data";

  2. var myvariable = "more data";




So, use good, consistent practices in your custom identifiers, to ensure that you don’t accidentally declare two different variables when you actually meant to create just one.

8. Use the switch Statement to Handle Multiple Conditions


Don’t do this:


  1. if (example_variable == "cyan") {

  2. // do something here...

  3. else if (example_variable == "magenta") {

  4. // do something here...

  5. else if (example_variable == "yellow") {

  6. // do something here...

  7. else if (example_variable == "black") {

  8. // do something here...

  9. else {

  10. // do something here...

  11. }




Do this:


  1. switch (example_variable) {

  2. case "cyan":

  3. // do something here...

  4. break;

  5. case "magenta":

  6. // do something here...

  7. break;

  8. case "yellow":

  9. // do something here...

  10. break;

  11. case "black":

  12. // do something here...

  13. break;

  14. default:

  15. // do something here...

  16. break;

  17. }




The second block of code does the exact same thing as the first — but the second one is cleaner, easier to read, and easier to maintain and modify.

9. Use try-catch to Prevent Errors From Displaying to the User


By wrapping all your code in a try-catch statement, you can ensure that the user never sees an ugly JavaScript error. Like this:


  1. try {

  2. nonExistentFunction();

  3. catch (error) {

  4. document.write("An error has occured.")

  5. }




In the code above, I’ve attempted to call a function that doesn’t exist, to force an error. The browser will not display the typical “not an object” or “object expected” error, but instead will display the custom error that I’ve included in the catch section. You could also leave the catch section empty, and then nothing will happen on the client side, or you could create a function to call inside the catch section to handle the error quietly for your own debugging purposes.

Keep in mind that this could cause errors to be hidden from the developer as well, so good code documentation and commenting would be helpful here.

10. Make Multi-Line Comments Readable, But Simple


In JavaScript, you can comment a line of code by putting // at the beginning of the line. You can also comment out a block of code as shown here: /* [code goes here] */. Sometimes you’ll need to include a longer, multi-line comment. A good method to use that is not too visually overwhelming, but is easy to spot in the code is as follows:


  1. /*

  2. * This is a multi-line comment ...

  3. * cont'd...

  4. * cont'd...

  5. * cont'd...

  6. * cont'd...

  7. */




That’s it, 10 easy JavaScript tips and best practices. Hopefully this article has added to the recent “best practices” articles that have been published and promoted. Please offer any suggestions or corrections in the comments, to add to the discussion, as I plan to expand on this in the future.


Read More Add your Comment 0 nhận xét


3 reasons why you should let Google host jQuery for you



Author Dave Ward on here

All too often, I find code similar to this when inspecting the source for public websites that use jQuery:



<script type="text/javascript" src="/js/jQuery.min.js"></script>



If you’re doing this on a public facing* website, you are doing it wrong.

Instead, I urge you to use the Google AJAX Libraries content delivery network to serve jQuery to your users directly from Google’s network of datacenters. Doing so has several advantages over hosting jQuery on your server(s): decreased latency, increased parallelism, and better caching.

In this post, I will expand upon those three benefits of Google’s CDN and show you a couple examples of how you can make use of the service.

* None of this is relevant to internal applications served over a LAN. It would be as likely harm performance as improve it.

Decreased Latency


A CDN — short for Content Delivery Network — distributes your static content across servers in various, diverse physical locations. When a user’s browser resolves the URL for these files, their download will automatically target the closest available server in the network.

In the case of Google’s AJAX Libraries CDN, what this means is that any users not physically near your server will be able to download jQuery faster than if you force them to download it from your arbitrarily located server.

There are a handful of CDN services comparable to Google’s, but it’s hard to beat the price of free! This benefit alone could decide the issue, but there’s even more.

Increased parallelism


To avoid needlessly overloading servers, browsers limit the number of connections that can be made simultaneously. Depending on which browser, this limit may be as low as two connections per hostname.

Using the Google AJAX Libraries CDN eliminates one request to your site, allowing more of your local content to downloaded in parallel. It doesn’t make a gigantic difference for users with a six concurrent connection browser, but for those still running a browser that only allows two, the difference is noticeable.

Better caching


Potentially the greatest (yet least mentioned) benefit of using the Google AJAX Libraries CDN is that your users may not need to download jQuery at all.

No matter how aggressive your caching, if you’re hosting jQuery locally then your users must download it at least once. A user may very well have dozens of identical copies of jQuery-1.3.1.min.js in their browser’s cache, but those duplicate files will be ignored when they visit your site for the first time.

On the other hand, when a browser sees multiple subsequent requests for the same Google hosted version of jQuery, it understands that these requests are for the same file. Not only will Google’s servers return a 304 “Not Modified” response if the file is requested again, but also instructs the browser to cache the file for up to one year.

This means that even if someone visits hundreds of sites using the same Google hosted version of jQuery, they will only have to download it once.

Implementation


By now, you’re probably convinced that the Google AJAX Libraries CDN is the way to go for your public facing sites that use jQuery. So, let me show you how you can put it to use.

Of the two methods available, this option is the one that Google recommends:
The google.load() approach offers the most functionality and performance.

For example:


<script type="text/javascript"
src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
// You may specify partial version numbers, such as "1" or "1.3",
// with the same result. Doing so will automatically load the
// latest version matching that partial revision pattern
// (i.e. both 1 and 1.3 would load 1.3.2 today).
google.load("jquery", "1.3.2");

google.setOnLoadCallback(function() {
// Place init code here instead of $(document).ready()
});
</script>



While there’s nothing wrong with this, and it is definitely an improvement over hosting jQuery locally, I don’t agree that it offers the best performance.

Firebug image of the longer loading time caused by jsapi

As you can see, loading, parsing, and executing jsapi delays the actual jQuery request. Not usually by a very large amount, but it’s an unnecessary delay. Tenths of a second may not seem significant, but they add up very quickly.

Worse, you cannot reliably use a $(document).ready() handler in conjunction with this load method. The setOnLoadCallback() handler is a requirement.

Back to basics


In the face of those drawbacks to the google.load() method, I’d suggest using a good ‘ol fashioned <script> declaration. Google does support this method as well.

For example:


<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
// This is more like it!
});
</script>



Not only does this method avoid the jsapi delay, but it also eliminates three unnecessary HTTP requests. I prefer and recommend this method.

Conclusion


According to a recent study, Google will consume 16.5% of all consumer Internet capacity in the United States during 2008. I think it’s fair to say that those guys know how to efficiently serve up some content.

The opportunity to let the pros handle part of your site’s JavaScript footprint free of charge is too good to pass up. As often as even returning users experience the “empty cache” load time of your site, it’s important to take advantage of an easy optimization like this one.

What do you think? Are you using the Google AJAX Libraries CDN on your sites? Can you think of a scenario where the google.load() method would perform better than simple <script> declaration?


Read More Add your Comment 1 nhận xét


 

About Me

Ảnh của tôi
I'm a web developer who wanna play with PHP (Zend/CodeIgniter/Kohana) MySQL, JS (jQuery, ExtJs, Prototype), CSS and HTML.

Our Partners

© 2010 Thy Trần's home. All Rights Reserved.