CSS hack:区分IE6,IE7,firefox,区别不同浏览器

区别不同浏览器,CSS hack写法:

区别IE6FF

       background:orange;*background:blue;
区别IE6IE7

       background:green !important;background:blue;
区别IE7FF

       background:orange*background:green;
区别FFIE7IE6

       background:orange;*background:green !important;*background:blue;
注:IE都能识别*;标准浏览器(如FF)不能识别*;

IE6能识别*,但不能识别 !important,

IE7能识别*,也能识别!important;

FF不能识别*,但能识别!important;


另外再补充一个,下划线"_",
IE6支持下划线,IE7和firefox均不支持下划线。于是大家还可以这样来区分IE6IE7firefox
: background:orange;*background:green;_background:blue;

注:不管是什么方法,书写的顺序都是firefox的写在前面,IE7的写在中间,IE6的写在最后面。


相关:
Posted in CSS | Tagged , , , | Leave a comment

ul li list-style学习笔记

list-style : list-style-image || list-style-position || list-style-type
默认值是 disc outside none;

项目符号图片:  list-style-image : none | url ( url )
                list-style-image  不设置,或者为none,或者所指向的image不存在时,才会采用 list-style-type 的符号
项目符号:      list-style-type : disc | circle | square | decimal | lower-roman | upper-roman | lower-alpha | upper-alpha | none
                假如一个列表项目的左外补丁( margin-left )被设置为 0 ,则列表项目标记不会被显示。左外补丁( margin-left )最小可以被设置为 30 。

项目符号位置:  list-style-position : outside | inside
                outside  : 默认值。列表项目标记放置在文本以外,且环绕文本不根据标记对齐
                inside  : 列表项目标记放置在文本以内,且环绕文本根据标记对齐
下面是测试代码 

<div style="width:100px;background-color:gray;color:#fff;">
 <ul>
  <li>这是第1行 这是第1行 这是第1行 这是第1行 这是第1行 这是第1行 这是第1行 这是第1行 这是第1行 这是第1行 这是第1行 这是第1行 这是第1行 这是第1行</li>
  <li>这是第2行 这是第2行 这是第2行 这是第2行 这是第2行 这是第2行 这是第2行 这是第2行 这是第2行 这是第2行 这是第2行 这是第2行 这是第2行 这是第2行</li>
  <li>这是第3行 这是第3行 这是第3行 这是第3行 这是第3行 这是第3行 这是第3行 这是第3行 这是第3行 这是第3行 这是第3行 这是第3行 这是第3行 这是第3行</li>
  <li>这是第4行 这是第4行 这是第4行 这是第4行 这是第4行 这是第4行 这是第4行 这是第4行 这是第4行 这是第4行 这是第4行 这是第4行 这是第4行 这是第4行</li>
 </ul> 
</div> 

应用的css是

* {
 margin: 0;
 padding: 0;
}

body {
 font-size: 12px;
}

ul {
 list-style: disc inside ;
 /*margin-left: 16px;*/
}

当ul的 list-style-position是 inside的时候 出现:

ul001.gif

当ul的 list-style-position是 outside的时候 出现:

ul002.gif

outside的项目标记,因为margin-left是0,看不到

当设置ul的margin-left:16px时, 效果如下:

ul003.gif

整个ul往右边移动了16px,位于outside位置的项目标识符号也就能够看到了。

Posted in CSS | Tagged , | Leave a comment

培养创造力的9种方法

来源: http://www.mifengtd.cn/articles/9-ways-of-cultivating-creativity.html

我相信创造力灵性之间是有联系的。这里的“灵性”指的不是某种宗教信仰,而是人类的精神,我们的根源。拥有它,使我们能够感受到与生命之间的息息相关。拿破仑·希尔把它称为“无穷的智慧”,Deepak Chopra 称之为“纯意识”。我的朋友 Joshua Roman 则用美丽的词藻将之形容为:“......我们心中的一片永无止境之地”。这个存在于我们心中的美好世界虽然无法用文字准确的描述,却可以用心感受到。

拥有创造力即意味着放松身心,进入自己内心的这一境界之中,运用所谓的“无穷的智慧”。这是我们每个人都拥有的天赋,它有待于你去发掘。我们每个人都是拥有才华的生命个体,因为我们都能够汲取相同的无尽之源。我们都天生被赋予了这样的厚礼。

从创造力出发时,我们拥有的是一片丰裕的土壤,不存在任何束缚。只有当我们从竞争的角度考虑时,限制和短缺才会被考虑进来。

所谓“更有创造性”是一种不恰当的说法。你本身就是一个具有创造性的个体。然而,你可以通过实践,使自己变得更加娴熟,或者更深入的理解围绕在你身边的创造能量,这种能量,是你在任何时候都可以无限汲取的。

我个人在实际中从以下九点来帮助自己“培养”创造力,希望能够给大家提供一些启发。

  • 处于放松状态

用点时间,做令自己感到愉快的、能够带来欢乐的、你热爱的或能够使自己全身投入的事情。比如沉思、散步、游泳、阅读令人心情愉快的文字,或者记日记——写下你的想法(这会相当有帮助!)。

想一想,什么赋予你积极向上、源源不断的能量与活力,从而使你心怀感激?当感受到对生命中得到的美妙祝福与馈赠,你的心中便有了爱,你会很快感到心灵的释然,内心感到朦胧的温暖。在这感受到温暖和爱意的时刻,你的心向创造力量敞开了大门。

  • 激发你的想象力

想象力是高度视觉化的。我发现,练习在闭上双眼的情况下,想象面前看到的栩栩如生的画面,是一种很有帮助的方法。

尝试这一方法。闭上双眼,想象自己在一个场景里,任何一个场景都可以。好的,选个你认为理想的场景,尝试想象你看到的这一场景中的细节。去注意各种色彩、质地,去触摸。它们摸起来是什么感觉?你听到了什么?闻到了什么?温度感觉是怎样的?等等。

  • 专注于此刻

每一位杰出的音乐家或艺术家都会告诉你,当他们在创造伟大的音乐或艺术品的时候,他们的头脑中没有任何杂念,他们完全沉浸在此刻的创作之中,感受意识的流动。运动员们把这个称作“现场感(being in the zone)”。你可以通过对你此刻做的任何事情(不管是在吃饭、洗碗、整理床铺,还是别的什么)倾注全部的注意力,来尝试练习仅把全部意识集中在当前时刻的能力。沉思可以起到很大帮助。参考阅读《如何保持注意力》。

  • 得到灵感

试着去想象打动你的美好事物。翻阅含有能够激发人思维的图片的书籍,参观美术馆,读启发人灵感的文字,与能够使你冷静的人交谈。

  • 画图

这也许听起来有些可笑,但确实是发掘自身创造力的有效方法之一。画图促使你从不同的角度观察事物。在这一点上,我强力推荐一本由Betty Edwards著的《像艺术家一样思考(Drawing on the Right Side of the Brain)》的书,以及她所写的与之配套的手册。这本书是专门为那些从未受到过绘画训练的人撰写的。我从一本心理学教材上第一次听说它,阅读后发现,自己从其中的深刻见解里学到很多东西。

  • 寻找替代方案

保持好奇心。试着问自己,如何以不同的方式完成同一件事情。 当你看到了一个问题的解决方案之后,再问一问自己:“有什么其他方式做这件事呢?”心理上建立起这样的一种态度——“总有另一种方法”,即便其他方法看起来似乎“不可行”时,也要如此。

  • 开放的心态

不要将任何你想到的点子拒之门外,不要轻易对它们作出判决。重视每一个从你的大脑里冒出来的主意,哪怕是那些看起来“愚蠢”或“显而易见”的想法。这个方法能够催生更多有创造性的想法从你的心中浮现出来。

  • 把思考过程落在纸上

用一叠活页纸(或者一个笔记本,我更愿意用活页纸,这样你不会因为要保持纸页的整洁和相互间的组织性而感到约束)。写下思考中你的大脑里冒出的一切:随意的词语、短语、主意、想法......有时,你也许会想要把一些元素圈在一起或在它们之间画线,来将不同的主意联系在一起。当灵感闪现时,一定要跟住它。这时如果你突然想到了另一个主意,先把它简略的记在同一张纸或另一张空白的纸上。这也是我组织博客文章的方法。我都是从一些念头和要点出发,有时候一开始它们还显得很蹩脚,但是一旦我进入了“思维流”里面,一篇文章就开始逐渐在我的眼前现出雏形。

Posted in 方法 | Tagged , , | Leave a comment

MySQL Storage Engines

MySQL Storage Engines

Mike Peters, 01-20-2008   来源  http://www.softwareprojects.com/resources/programming/t-mysql-storage-engines-1470.html

One of the greatest things about MySQL, other than being free, widely supported and fast, is the flexibility of choosing different storage engines for different tables.

Out of the box, MySQL comes with 7 storage engines, including an "example" stub storage engine that allows you to implement your own storage library.

What's the big deal about having all these options?

Every storage engine is completely different, designed to address a unique application need.

Not being locked down to a single storage engine (like Oracle), means you can optimize and choose the best tool for the job.

Tip: A well designed MySQL-powered application will use different storage engines for different tables. If you're still stuck with all MyISAM tables, now may be a good time to revisit.

MySQL Storage Engines Overview

MyISAM: The default engine. No transactions support, average data reliability. Offers great performance for read heavy applications. Most web services and data warehousing applications use MyISAM heavily.

HEAP: All in-memory. Very fast for data retrieval, however due to being stored only in memory - all data is lost on shutdown. Great for temporary tables.

Archive: Used for storing large amounts of data without indexes in a small footprint.

Merge: Collection of MyISAM tables logically merged together to provide a single view.

InnoDB: Transaction-safe storage engine, best suited for write heavy environments thanks to row-level locking. Offers good built-in recovery and solid data reliability. InnoDB engine was acquired by Oracle on 2005.

NDB: A clustered engine - data is automatically split and replicated across several machines, a.k.a data nodes. Best suited for applications that require high performance lookups with the highest possible degree of uptime and availability. Originally designed by Ericsson for the Telco market, NDB offers the highest levels of data reliability (99.999%). NDB works well in read heavy environments. For write heavy environments with multiple concurrent writes, consider InnoDB.

The biggest disadvantadge of NDB, is that by design your entire database must fit in memory. If your database size times 2 is too big to fit in memory, NDBCluster is not for you.

-

To make it easier to follow the unique characteristics of each storage engine, I created this magic quadrant diagram:


Examples:

Below are some examples of using the best storage engine for different tasks:

Search Engine - NDBCluster

Web stats logging - Flat file for the logging with an offline processing demon processing and writing all stats into InnoDB tables.

Financial Transactions - InnoDB

Session data - MyISAM or NDBCluster

Localized calculations - HEAP

Dictionary - MyISAM

Important notes about MyISAM tables:

1. Your tables will get corrupted eventually! Plan accordingly.

Tar the entire database directory daily and setup MySQL replication to a slave for an up-to-the-minute live backup.

2. Turn on auto-repair by adding this flag to your my.cnf file:
myisam-recover=backup,force

Or consider running a check-all-tables-and-email-me cronjob daily: See our MySQL Table Maintenance automation.

3. Super fast for read (select) operations.

4. Concurrent writes lock the entire table. Switch everything to offline processing where you can, to serialize writes without taking the database down. (Offline processing is golden and applies to all table types)

Important notes about HEAP/Memory tables:

While this type of table offers super fast retrieval, it only works well for small temporary tables.

If you try to load too much data into a Memory table, MySQL will start swapping information to disk and then you lose the benefits of an all-memory storage.

Important notes about InnoDB tables:

1. ACID transactions support. Row-level locking (compared to table level locking with MyISAM) means faster concurrent writes.

2. Doing a "SELECT Count(*) FROM table" without specifying any indexes is very slow on InnoDB and requires a full table scan. (With MyIsam this operation doesn't cost anything because MyIsam stores an internal record counter with each table).

If you need to "SELECT COUNT(*)" often on InnoDB tables, create MySQL insert/delete triggers that will increment/decrement a counter whenever records are added or deleted from the table.

3. Backup:

Doing a tar/rsync backup where you simply copy all files is not possible with InnoDB.

MySQLDump backup is too slow with InnoDB. (If you insist on using it, turn on these flags: --opt --compress)

The only viable fast backup option, which can also be used to populate new slave machines, is InnoDB Hot Backup.

4. Recovery:

InnoDB has built-in recovery that works 99% of the times automatically. Never try to move .frm or .ibd files around as a way of "helping" the database to recover. If the built-in recovery doesn't work, switch to your slave server and restore the primary from backup.

5. LOAD DATA INFILE is too slow with InnoDB. Consider using MyIsam tables for LOAD DATA operations.

6. InnoDB is less forgiving than MyIsam when it comes to queries on non indexes. InnoDB is going to "School" you into ensuring every single query and update statement runs on an index. Issue no index queries and you'll pay dearly in execution time.

7. Never ever change my.cnf INnoDB log file size while the database is running. You'll corrupt the log sequence number beyond repair.

8. To maximize InnoDB MySQL database performance, start with these my.cnf settings:

innodb_open_files = 500
innodb_file_per_table
innodb_buffer_pool_size = 250M
innodb_flush_log_at_trx_commit = 2
innodb_thread_concurrency =8
innodb_lock_wait_timeout = 500
interactive_timeout = 20
back_log = 75
table_cache = 300
thread_cache = 32
thread_concurrency = 8
wait_timeout = 30
connect_timeout = 10

9. If InnoDB crashes and the built-in recovery mechanism is unable to roll-back transactions, your database will not start. This is very important to understand. With MyISAM, even if a table gets corrupted, you can still start the database and everything will work normally. InnoDB will simply refuse to start until you restore the entire database from backup. Make sure you understand this principle and backup religiously.

Scalability:

Every successful web application eventually outgrows the capacity and throughput of a single database machine.

At that point you typically have two options - Replication or NDBCluster.

As always the choice depends on the needs of your application.

For read-heavy environments, use an NDBCluster or setup replication for n MyISAM slave read-only machines.

For write-heavy environments, InnoDB on an active/passive replication setup is typically the best choice. You may also want to experiment with an NDBCluster. An NDBCluster is generally going to be slower than InnoDB in write-heavy environments, but it offers a higher level of availability.

Helpful Scripts:

* Convert all tables to InnoDB

* MySQLDump one database to another (designed for a case where you cannot use InnoDB Hot backup and you have a lot of tables/databases to import. Script automatically retries, reopens connection and imports one table at a time)

* Add triggers to all tables for fast InnoDB count(*)
You can only have one delete/insert trigger per each table so if you're already using triggers, modify the code accordingly.

Posted in 优化专题 | Tagged , , | Leave a comment

《新结婚时代》经典台词

你可以不爱江山爱美人,但是告诉你,没有一个美人是不爱江山的。
如果他没有把你介绍给他的家人,那就是把自己还留有余地。
娶妻娶德,纳妾纳色。
一个男人要想对女人有很高的要求,他首先应该对自己有很高的要求,否则他就会像一个对生活品质有要求的乞丐一样让人生厌!
一个男人如果没有能力使自己立足于世,你有什么资格要求你梦想中的女人按照你的想法生活?
如果要想知道小鸟是不是属于你的,就别把它关在笼子里。
谎言有两种,一种是把黑说成白,一种是把黑的隐藏了(顾小航)
我不是不相信你的真诚,我是不相信你的年龄(简佳拒绝顾小航时说的话)
现在的择偶标准是,有车有房,父母双亡(顾小西告诉简佳找男朋友的条件,够绝!)
已经上了钩的鱼就不用再浪费鱼饵了(何建国的同事)
结婚你不是嫁给了某一个人,而是嫁给了这个人的全部社会关系。你们俩的结合就是两个家庭的结合,他娶了你,就等于娶了你的一切,包括你的社会关系、你的父母……(顾小西妈妈)
钱有多多,爱有多深(顾小西)
你是在卖书,还是在卖有暗香盈袖春(顾小西-关于陈蓝发书书名被迫改成‘我包养的三年’)
这世界上没有无缘无故的爱!
这个世界上只有两种女人,一种是假正经的,一种是假不正经的。
女人怀孕九个月生完孩子还要半年要花一年多时间,你们男人也就出那么十几分钟的力。
如果可以,我将告诉所有的女孩子,千万别和结婚的男人有染。——BY简佳
爱情并不比亲情更重要——BY简佳。
追求精致生活的人,吃饭是精致生活的第一要素。
不是只看外表,是先看外表。
 

Posted in 谈资 | Tagged , | Leave a comment

推荐一个Blog《新春秋》http://daimones.blogspot.com/

来源 http://www.hecaitou.net/?p=2706

《新春秋》(不用点了,Blogspot的,你在祖国大陆的话访问不了),全名是《新春秋 PANDEMONIUM》,不过请叫它的中文名。这是一个香港的集体Blog,可以称之为中国第一人文Blog Network。大陆有许多Blog Network,大多都是技术类Blog,人文类的很少。不过这可以理解,因为没有谁愿意开一个Blog是为了尽早被关掉。所以,《新春秋》的出现让我感觉很新鲜,觉得上网不总是重复。

在使用中文的Blogger中,由于字体的不同而被分为简体字和繁体字两大群落。长期以来,这两边的人很少走动。据我所知,台湾的Blog日流量没有超过1万的。这就说明了大家彼此之间的隔膜,证明大陆访客并不经常出去走走。我不知道这是因为什么而形成的,台湾的Blogger我就认识三个人:Ken(工头坚部落)、Carol(太妃糖忧郁狂欢节)、红色长角三倍速,而香港的Blogger我一个都不认识。在我目光所及,基本上看不到繁体字的Blog。事实上,我也去过香江那边,海峡对面,但是他们关心的事情是我不关心的,而且网速相当影响心情。

《新春秋》的出现算是个异类,我最早是看到关于艳莫道不消魂照门的一篇评论《淫照不能存,威武实能曲》,内容是用粤语写成,但是看了以后极赞。注意到作者奇怪的ID左冷禅,又看到Blog标题《新春秋》,于是就留心上了。不久之后,《新春秋》在豆瓣九点变得极为火爆,经常能在二套节目中看到它的身影。和《新春秋》的一位作者联系上之后,总算对它有了一个初步的了解。

简单讲,《新春秋》就是香港的各种牛鬼蛇神的大汇集。各位《新春秋》的作者都有自己的术业专攻,而且数量众多,所以在深度和广度上都让人非常赞叹。《新春秋》没有什么水文,只有干货,所以看起来很解瘾。而这么一班人可以聚集起来,在一个Blog里写东西,更是出奇。因为在我们这里,他们很可能早就各自独立,演变成一堆Blog。我时常想,难道他们的背后也有一个“带头大哥”?可以把那么多神道怪物聚集在一起,而且还相安无事?

由于大陆无法访问《新春秋》,这里提供以下他们的相关地址:

1、RSS地址
2、豆瓣九点地址
3、豆瓣讨论组地址

最后,附上一篇他们的自我介绍:

什么是新春秋/Pandemonium?

Sunt bona, sunt quaedam mediocria, sunt mala plura
quae legis hic. aliter non fit, Avite, liber.

好东西,一些平凡的东西,更多糟糕的东西,
你都在这儿读到。若非这样,阿维陀,书就造不成了。

---Martial, I, xvi

越厚的书就是越大的烦恼,但越乱的书呢?不论中外,古代的书生都爱写一些读书札记或见闻随笔之类的东西,例如Aulus Gellius 的《阿提卡之夜》(Noctes Atticae‎)、Macrobius的《冬夜谈》 (Saturnalia)、甚至Robert Burton的《忧郁解剖》(Anatomy of Melancholy),都是随兴而发,谈锋乱指,又充斥着各种玄思妙想和冷僻知识的奇书;这种感悟式笔记,在旧中国更是蔚为奇观,像钱锺书先生的《管锥编》,若以西方学术规格则之,自然非驴非马,但置诸这个笔记传统,则明显是部划时代的经典之作。这类书的特色,就是随便翻开一页也可读,甚至逆着页数来看也别具风味。更可爱的,是章节间不必有任何联系,而上页和下页也不用斤斤计较是否连贯,所以每翻一页,心情就好比小孩要拆开一份神秘的圣诞礼物,夹杂着期待的喜悦、好奇的刺激和害怕愿望落空的焦虑。

一直想读这样的书﹕每页都由不同作者来写,时而因己所长,围绕同一主题抒发见解,甚至互相辩论或嘲讽,时而又会忽然离题万丈、东拉西扯,不断测试读者耐性的底线。每句每页每章都不可预测,看似绝不相干却又藕断丝连,彷佛胡说八道但又言之有物。我跟朋友都喜欢这样对话,也希望可以这样写作。把这种在过去很普通,但在今日却显得有点诡异的说话模式记录下来,就是Pandemonium的原意。我们都是胸无大志的三流知青,没有改变社会的能力或兴致,更没意图提升青少年的道德和品味;谈不上志同道合,只打算拳来脚往;没想过以文会友,极其量是狼狈为奸。我要大力强调:这不是“言在此而意在彼”的反讽,而是真实不虚的宣誓。

Pandemonium的运作只有一大原则:乱。那是一本没有设定主题和连贯风格的书,注定是妍媸互显,但愿不会玉石俱焚。现在已受骗参与的,以职业计,有厨师、法师、律师、教师和测量师(主要负责“量地”);以专业论,则有阅读、驱鬼、行骗、参禅、吃饭、谩骂、失踪、玩命等。我们计划网罗的,还包括编辑、主妇、推销员、易服僻、学生、编剧、黑瑞脑消金兽社会、间谍、嫖客、道友、和尚、设计师、IT人、那些因为写blog而悟出如何说废话的行政人员、因为当了只讲不做的行政领佳节又重阳导而学懂如何写作的blogger......作者人数没有上限,如果---只是如果---有365位组员,我们每人只要每年一篇,就可以令网站天天更新,而内容也会荒谬地丰富。

可以这样 说,我跟我所认识的朋友,绝大部分都非常懒散。要我们咬紧牙关定期更新,做一个负责任的blogger,就好像Dr Johnson为字典编纂者(Lexicographer)所下的定义般,岂不是成为一个“无害的苦工”(a harmless drudge)?说穿了,合写的终极功能不是要联群结党,而是齐心偷懒。正面一点说,也可以让那些没空闲写blog的朋友有机会偶然露一两手。互联网说普及吗?但我家中有三分二人根本不上网,我大部分朋友也极少在网上发言,要扩阔这个如此简便的信息平台,最实际的方法,就是把那些只活在三度空间的人拉入这个更多佳节又重阳维的网海,藉此丰富那个虚拟世界的精神网络。不要害怕跟你不同的人,他们不会削弱而只会増强你的自我。

“新春秋”这个中文名字,说来也有一段传奇。话说半个月前,无聊的传惑子要跟朋友创立一个诗社,因为想不到好的名字,便灵机一动:何不召诗仙李白下来为诗社命名呢?于是这位精通道教科仪的天主教徒传惑子,便立即画符念咒请诗仙降临---然后肃穆地摊开一份《明报》,再恭敬地掷了两次毫,而硬币击中的,正是“比事”二字,出《礼记.经解》:“属辞比事,《春秋》教也”,意即熟习《春秋》者,则擅长属辞比事(所谓“比事”,孙希旦解作“比次列国之事而书之也”)。故此传惑子本打算把诗社定名为“春秋”,可惜本港早有一个春秋诗社,不好抄袭别人,但又想不出一个能跟“比事”相关的名字。上周末见面,他便顺道问我的看法。我想了一想便说: “这件事易办。既然地产商有新鸿基、黑瑞脑消金兽社会有新义安,你为什么不叫新春秋呢?至于那‘诗社’二字,太闷艺青年了,看了令人齿冷,倒不如简简单单叫‘新春秋 ’更有爽气。不知情的人听到,也许还会美丽地误会你是某社团的话事人,恐怕还会多敬重你三分。”

“孔子成《春秋》而乱臣贼子惧”---“春秋”,本来就象征一种井然的秩序,和Pandemonium(可以有三重含意)放在一起,正好是一个硬币的两面。这里没有二元的对立,只是辩证地统一,就像现实世界。

P.S. 我会广发电邮邀请加入,你也可以自投罗网,过路的、不相识的也无任欢迎:

magliabecchi@gmail.com

Posted in 博客推荐 | Tagged , , | Leave a comment

Mysql SHOW PROCESSLIST Sending data 优化

我的系统在实际应用中当show processlist的时候看到大多时候都是Sending data!也就是我一直非常奇怪为什么会有这么多Sending data 滞留在我的系统中,真是往客户端发送查询结果不应该这么慢的!
文档上说:Sending data The thread is processing rows for a SELECT statement and is also sending data to the client.
我特别想要说明的是黄底部分的,虽然字面上看起来好像这个状态意味着在给客户端发送数据而已,实际上不完全是这样的,比如MySQL找到查询结果(30条记录,没有Cache到内存中,散布在硬盘上不同的地方)了,这样的话实际上要从这30个不同的地方取出这30条记录,也就是要寻道30次(特别散,Cache不到 :) ),这个任务我觉得可以看成
The thread is processing rows for a SELECT statement 这个时候也许要想办法去增加内存,让MySQL不但将Index能Cache到内存中,才能够更多地将具体数据Cache到内存中了!

来自MySQL手册:

6.5.5.2. General Thread States

The following list describes thread State values that are associated with general query processing and not more specialized activities such as replication. Many of these are useful only for finding bugs in the server.

  • After createOccurs when the thread creates a table (including internal temporary tables), at the end of the function that creates the table. This state is used even if the table could not be created due to some error.
  • AnalyzingThe thread is calculating a MyISAM table key distributions (for example, for ANALYZE TABLE).
  • Checking tableThe thread is performing a table check operation.
  • cleaning upThe thread has processed one command and is preparing to free memory and reset certain state variables.
  • closing tablesMeans that the thread is flushing the changed table data to disk and closing the used tables. This should be a fast operation. If not, you should verify that you do not have a full disk and that the disk is not in very heavy use.
  • converting HEAP to MyISAMThe thread is converting an internal temporary table from a MEMORY table to an on-disk MyISAM table.
  • copy to tmp tableThe thread is processing an ALTER TABLE statement. This state occurs after the table with the new structure has been created but before rows are copied into it.
  • Copying to group tableIf a statement has different ORDER BY and GROUP BY criteria, the rows are sorted by group and copied to a temporary table.
  • Copying to tmp tableThe server is copying to a temporary table in memory.
  • Copying to tmp table on diskThe server is copying to a temporary table on disk. The temporary result set was larger than tmp_table_size and the thread is changing the temporary table from in-memory to disk-based format to save memory.
  • Creating indexThe thread is processing ALTER TABLE ... ENABLE KEYS for a MyISAM table.
  • Creating sort indexThe thread is processing a SELECT that is resolved using an internal temporary table.
  • creating tableThe thread is creating a table. This includes creation of temporary tables.
  • Creating tmp tableThe thread is creating a temporary table in memory or on disk. If the table is created in memory but later is converted to an on-disk table, the state during that operation will be Copying to tmp table on disk.
  • deleting from main tableThe server is executing the first part of a multiple-table delete. It is deleting only from the first table, and saving fields and offsets to be used for deleting from the other (reference) tables.
  • deleting from reference tablesThe server is executing the second part of a multiple-table delete and deleting the matched rows from the other tables.
  • discard_or_import_tablespaceThe thread is processing an ALTER TABLE ... DISCARD TABLESPACE or ALTER TABLE ... IMPORT TABLESPACE statement.
  • endThis occurs at the end but before the cleanup of ALTER TABLE, CREATE VIEW, DELETE, INSERT, SELECT, or UPDATE statements.
  • Execution of init_commandThe thread is executing statements in the value of the init_command system variable.
  • freeing itemsThe thread has executed a command. This state is usually followed by cleaning up.
  • Flushing tablesThe thread is executing FLUSH TABLES and is waiting for all threads to close their tables.
  • FULLTEXT initializationThe server is preparing to perform a natural-language full-text search.
  • initThis occurs before the initialization of ALTER TABLE, DELETE, INSERT, SELECT, or UPDATE statements.
  • KilledSomeone has sent a KILL statement to the thread and it should abort next time it checks the kill flag. The flag is checked in each major loop in MySQL, but in some cases it might still take a short time for the thread to die. If the thread is locked by some other thread, the kill takes effect as soon as the other thread releases its lock.
  • LockedThe query is locked by another query.
  • logging slow queryThe thread is writing a statement to the slow-query log.
  • loginThe initial state for a connection thread until the client has been authenticated successfully.
  • Opening tables, Opening tableThe thread is trying to open a table. This is should be very fast procedure, unless something prevents opening. For example, an ALTER TABLE or a LOCK TABLE statement can prevent opening a table until the statement is finished.
  • preparingThis state occurs during query optimization.
  • Purging old relay logsThe thread is removing unneeded relay log files.
  • query endThis state occurs after processing a query but before the freeing items state.
  • Reading from netThe server is reading a packet from the network.
  • Removing duplicatesThe query was using SELECT DISTINCT in such a way that MySQL could not optimize away the distinct operation at an early stage. Because of this, MySQL requires an extra stage to remove all duplicated rows before sending the result to the client.
  • removing tmp tableThe thread is removing an internal temporary table after processing a SELECT statement. This state is not used if no temporary table was created.
  • renameThe thread is renaming a table.
  • rename result tableThe thread is processing an ALTER TABLE statement, has created the new table, and is renaming it to replace the original table.
  • Reopen tablesThe thread got a lock for the table, but noticed after getting the lock that the underlying table structure changed. It has freed the lock, closed the table, and is trying to reopen it.
  • Repair by sortingThe repair code is using a sort to create indexes.
  • Repair doneThe thread has completed a multi-threaded repair for a MyISAM table.
  • Repair with keycacheThe repair code is using creating keys one by one through the key cache. This is much slower than Repair by sorting.
  • Rolling backThe thread is rolling back a transaction.
  • Saving stateFor MyISAM table operations such as repair or analysis, the thread is saving the new table state to the .MYI file header. State includes information such as number of rows, the AUTO_INCREMENT counter, and key distributions.
  • Searching rows for updateThe thread is doing a first phase to find all matching rows before updating them. This has to be done if the UPDATE is changing the index that is used to find the involved rows.
  • Sending dataThe thread is processing rows for a SELECT statement and also is sending data to the client.
  • setupThe thread is beginning an ALTER TABLE operation.
  • Sorting for groupThe thread is doing a sort to satisfy a GROUP BY.
  • Sorting for orderThe thread is doing a sort to satisfy a ORDER BY.
  • Sorting indexThe thread is sorting index pages for more efficient access during a MyISAM table optimization operation.
  • Sorting resultFor a SELECT statement, this is similar to Creating sort index, but for non-temporary tables.
  • statisticsThe server is calculating statistics to develop a query execution plan.
  • System lockThe thread is going to request or is waiting for an external system lock for the table. If you are not using multiple mysqld servers that are accessing the same tables, you can disable system locks with the --skip-external-locking option.
  • Table lockThe next thread state after System lock. The thread has acquired an external lock and is going to request an internal table lock.
  • UpdatingThe thread is searching for rows to update and is updating them.
  • updating main tableThe server is executing the first part of a multiple-table update. It is updating only the first table, and saving fields and offsets to be used for updating the other (reference) tables.
  • updating reference tablesThe server is executing the second part of a multiple-table update and updating the matched rows from the other tables.
  • User lockThe thread is going to request or is waiting for an advisory lock requested with a GET_LOCK() call.
  • Waiting for tables, Waiting for tableThe thread got a notification that the underlying structure for a table has changed and it needs to reopen the table to get the new structure. However, to reopen the table, it must wait until all other threads have closed the table in question.

    This notification takes place if another thread has used FLUSH TABLES or one of the following statements on the table in question: FLUSH TABLES tbl_name, ALTER TABLE, RENAME TABLE, REPAIR TABLE, ANALYZE TABLE, or OPTIMIZE TABLE.

  • Waiting on condA generic state in which the the thread is waiting for a condition to become true. No specific state information is available.
  • Writing to netThe server is writing a packet to the network
Posted in 优化专题 | Tagged , , , , | Leave a comment

Nginx + PHP5(FastCGI)生产环境跑PHP动态程序可超过“700次请求/秒”

来源:  http://blog.s135.com/read.php/?334

  我生产环境下的两台Nginx + PHP5(FastCGI)服务器,跑多个一般复杂的纯PHP动态程序,从Nginx的日志可以统计出,单台Nginx + PHP5(FastCGI)服务器跑PHP动态程序的处理能力已经超过“700次请求/秒”,相当于每天可以承受6000万(700*60*60*24=60480000)的访问量:

  服务器①:DELL PowerEdge 1950(两颗 Intel(R) Xeon(R) 双核CPU 5120 @ 1.86GHz,4GB内存)

  服务器②:DELL PowerEdge 1950(一颗 Intel(R) Xeon(R) 双核CPU 5140 @ 2.33GHz,4GB内存)

  Web服务器:CentOS Linux 4.4 + Nginx 0.5.35 + PHP 5.2.6RC2(300 FastCGI Procees, unix-domain socket, with XCache)

  PHP程序内容:大量Memcached读写、少量MySQL读操作、大量文件队列写操作,然后计算,生成供<script type="text/javascript" src="http://www.domain.com/abc.php?u=1"></script>方式调用的JS代码或XML数据。

  网卡流量:1.5M~3M/秒

  请求数统计方式:从Nginx访问日志中,统计每分钟的第15秒共有多少条日志记录。

引用

grep "25/Mar/2008:15:01:15" /data1/logs/nginx.log | wc -l

  点击在新窗口中浏览此图片

  服务器的系统负载也不算高:

  点击在新窗口中浏览此图片

  总结:
  1、Nginx的处理能力超强,这块不是瓶颈。影响动态程序处理能力的因素主要在于PHP(FastCGI)。PHP(FastCGI)模式适用于执行时间较短的PHP程序,一般复杂的PHP程序执行时间应该在100ms以内,例如我的博客首页执行时间为38ms左右。假设一个PHP程序的执行时间为100ms,那么一个PHP(FastCGI)进程每秒可以处理完毕10个请求,300个FastCGI进程理论上每秒可以处理3000个请求。但是,在生产环境下,还将受到内存、系统负载等多方面的影响,例如300个PHP(FastCGI)进程需要占用2.4GB左右的内存,每秒处理超过1000个请求时,系统负载会飚升到100以上。因此,FastCGI的进程不是越多越好,而是够用就好。

  2、使用PHP的XCache、APC等加速模块会提供速度10倍左右,降低系统负载50倍以上。

  3、修改了spawn-fcgi,使它能够支持250个以上的FastCGI进程。

  4、如果PHP直接对MySQL进行大量读写操作,速度是达不到“700 request/sec”的,PHP与MySQL之间需要一个中间层,这是关键的技术。

  5、CPU的数量(多核算多个CPU,cat /proc/cpuinfo |grep -c processor)越多,系统负载越低,每秒能处理的请求数也越多。

  6、使用PHP 5.2.6RC2,因为它修正了PHP 5.2.5的“zend_mm_heap corrupted”错误BUG。PHP 5.2.5(FastCGI)在高并发请求情况下,经常会出现该错误。

  7、有空我将写一篇针对CentOS Linux环境Nginx + PHP5(FastCGI)安装、配置的最新博文。

Tags: , , , , , ,

Posted in 优化专题 | Tagged , , , , | Leave a comment

用ZenPhoto构建在线相册

对于有个人主机的朋友来说,除了可以使用Flickr或Yupoo这样的在线相册服务外,还有一种途径也值得一试,那就是用开源的相册软件来自已架设一个在线相册服务,这样就不必受制于人,完全掌控自已的照片。

最近我也有此想法,本来想选择Gallery2来进行架设,但它的功能过于强大,个人根本用不到如此多的功能,所以在一番寻找和选择后,最终选定了这个名为ZenPhoto的软件。

ZenPhoto是一款小巧的相册软件,基于PHP+MySQL技术构建,另需GD库支持。它安装方便,扩展性强,可轻易安装各类模版及插件,并可与WordPress整合。具备RSS输出、FTP上传方式、Tag功能、评论回复等功能。

官方主页:http://www.zenphoto.org/
目前版本:1.1.5
DEMO地址:http://blog.bsdos.cn/photogallery/

Posted in 网站程序 | Tagged , | Leave a comment

推荐凤凰卫视专题《台湾民瑞脑消金兽主之路》

《凤凰卫视》一贯被打击为香港CCTV第二,不过这次他们这个专题做得不错,值得推荐!

台湾民瑞脑消金兽主之路

Posted in 电视节目 | Tagged | Leave a comment