һƪ³¬ÊµÓõķþÎñÒì³£´¦ÀíÖ¸ÄÏ(2)
1.·½·¨Çø Ò²³Æ”ÓÀ¾Ã´ú” ¡¢“·Ç¶Ñ”£¬ËüÓÃÓÚ´æ´¢ÐéÄâ»ú¼ÓÔصÄÀàÐÅÏ¢¡¢³£Á¿¡¢¾²Ì¬±äÁ¿¡¢ÊǸ÷¸öÏ̹߳²ÏíµÄÄÚ´æÇøÓò¡£Ä¬ÈÏ×îСֵΪ 16 MB£¬×î´óֵΪ 64 MB£¬¿ÉÒÔͨ¹ý-XX: PermSize ºÍ -XX: MaxPermSize ²ÎÊýÏÞÖÆ·½·¨ÇøµÄ´óС¡£ ÔËÐÐʱ³£Á¿³Ø£ºÊÇ·½·¨ÇøµÄÒ»²¿·Ö£¬ClassÎļþÖгýÁËÓÐÀàµÄ°æ±¾¡¢×ֶΡ¢·½·¨¡¢½Ó¿ÚµÈÃèÊöÐÅÏ¢Í⣬»¹ÓÐÒ»ÏîÐÅÏ¢Êdz£Á¿³Ø£¬ÓÃÓÚ´æ·Å±àÒëÆ÷Éú³ÉµÄ¸÷ÖÖ·ûºÅÒýÓã¬Õⲿ·ÖÄÚÈݽ«ÔÚÀà¼ÓÔغó·Åµ½·½·¨ÇøµÄÔËÐÐʱ³£Á¿³ØÖС£ 2.ÐéÄâ»úÕ» ÃèÊöµÄÊÇjava ·½·¨Ö´ÐеÄÄÚ´æÄ£ÐÍ£ºÃ¿¸ö·½·¨±»Ö´ÐеÄʱºò ¶¼»á´´½¨Ò»¸ö“Õ»Ö¡”ÓÃÓÚ´æ´¢¾Ö²¿±äÁ¿±í(°üÀ¨²ÎÊý)¡¢²Ù×÷Õ»¡¢·½·¨³ö¿ÚµÈÐÅÏ¢¡£ ÿ¸ö·½·¨±»µ÷Óõ½Ö´ÐÐÍêµÄ¹ý³Ì£¬¾Í¶ÔÓ¦×ÅÒ»¸öÕ»Ö¡ÔÚÐéÄâ»úÕ»ÖдÓÈëÕ»µ½³öÕ»µÄ¹ý³Ì¡£ÉùÃ÷ÖÜÆÚÓëÏß³ÌÏàͬ£¬ÊÇÏß³Ì˽Óеġ£ ¾Ö²¿±äÁ¿±í´æ·ÅÁ˱àÒëÆ÷¿ÉÖªµÄ¸÷ÖÖ»ù±¾Êý¾ÝÀàÐÍ(boolean¡¢byte¡¢char¡¢short¡¢int¡¢float¡¢long¡¢double)¡¢¶ÔÏóÒýÓÃ(ÒýÓÃÖ¸Õ룬²¢·Ç¶ÔÏó±¾Éí)£¬ÆäÖÐ64볤¶ÈµÄlongºÍdoubleÀàÐ͵ÄÊý¾Ý»áÕ¼ÓÃ2¸ö¾Ö²¿±äÁ¿µÄ¿Õ¼ä£¬ÆäÓàÊý¾ÝÀàÐÍÖ»Õ¼1¸ö¡£ ¾Ö²¿±äÁ¿±íËùÐèµÄÄÚ´æ¿Õ¼äÔÚ±àÒëÆÚ¼äÍê³É·ÖÅ䣬µ±½øÈëÒ»¸ö·½·¨Ê±£¬Õâ¸ö·½·¨ÐèÒªÔÚÕ»Ö¡ÖзÖÅä¶à´óµÄ¾Ö²¿±äÁ¿ÊÇÍêÈ«È·¶¨µÄ£¬ÔÚÔËÐÐÆÚ¼äÕ»Ö¡²»»á¸Ä±ä¾Ö²¿±äÁ¿±íµÄ´óС¿Õ¼ä¡£ 3.±¾µØ·½·¨Õ» ÓëÐéÄâ»úÕ»»ù±¾ÀàËÆ£¬Çø±ðÔÚÓÚÐéÄâ»úջΪÐéÄâ»úÖ´ÐеÄjava·½·¨·þÎñ£¬¶ø±¾µØ·½·¨Õ»ÔòÊÇΪNative·½·¨·þÎñ¡£ 4.¶Ñ Ò²½Ð×öjava ¶Ñ¡¢GC¶ÑÊÇjavaÐéÄâ»úËù¹ÜÀíµÄÄÚ´æÖÐ×î´óµÄÒ»¿éÄÚ´æÇøÓò£¬Ò²ÊDZ»¸÷¸öÏ̹߳²ÏíµÄÄÚ´æÇøÓò£¬ÔÚJVMÆô¶¯Ê±´´½¨¡£ ¸ÃÄÚ´æÇøÓò´æ·ÅÁ˶ÔÏóʵÀý¼°Êý×é(ËùÓÐ new µÄ¶ÔÏó)¡£Æä´óСͨ¹ý -Xms (×îСֵ) ºÍ -Xmx (×î´óÖµ) ²ÎÊýÉèÖã¬-XmsΪ JVM Æô¶¯Ê±ÉêÇëµÄ×îСÄڴ棬ĬÈÏΪ²Ù×÷ϵͳÎïÀíÄÚ´æµÄ 1/64 µ«Ð¡ÓÚ 1G£» -Xmx Ϊ JVM ¿ÉÉêÇëµÄ×î´óÄڴ棬ĬÈÏΪÎïÀíÄÚ´æµÄ1/4µ«Ð¡ÓÚ 1G£¬Ä¬Èϵ±¿ÕÓà¶ÑÄÚ´æСÓÚ 40% ʱ£¬JVM »áÔö´ó Heap µ½ -Xmx Ö¸¶¨µÄ´óС£¬¿Éͨ¹ý -XX:MinHeapFreeRation= À´Ö¸¶¨Õâ¸ö±ÈÁУ» µ±¿ÕÓà¶ÑÄÚ´æ´óÓÚ70%ʱ£¬JVM »á¼õС heap µÄ´óСµ½ -Xms Ö¸¶¨µÄ´óС£¬¿Éͨ¹ýXX:MaxHeapFreeRation= À´Ö¸¶¨Õâ¸ö±ÈÁУ¬¶ÔÓÚÔËÐÐϵͳ£¬Îª±ÜÃâÔÚÔËÐÐʱƵ·±µ÷Õû Heap µÄ´óС£¬Í¨³£ -Xms Óë -Xmx µÄÖµÉè³ÉÒ»Ñù¡£ ÓÉÓÚÏÖÔÚÊÕ¼¯Æ÷¶¼ÊDzÉÓ÷ִúÊÕ¼¯Ëã·¨£¬¶Ñ±»»®·ÖΪÐÂÉú´úºÍÀÏÄê´ú¡£ÐÂÉú´úÖ÷Òª´æ´¢Ð´´½¨µÄ¶ÔÏóºÍÉÐδ½øÈëÀÏÄê´úµÄ¶ÔÏó¡£ÀÏÄê´ú´æ´¢¾¹ý¶à´ÎÐÂÉú´úGC(Minor GC)ÈÎÈ»´æ»îµÄ¶ÔÏó¡£ 5.³ÌÐò¼ÆÊýÆ÷ ÊÇ×îСµÄÒ»¿éÄÚ´æÇøÓò£¬ËüµÄ×÷ÓÃÊǵ±Ç°Ïß³ÌËùÖ´ÐеÄ×Ö½ÚÂëµÄÐкÅָʾÆ÷£¬ÔÚÐéÄâ»úµÄÄ£ÐÍÀ×Ö½ÚÂë½âÊÍÆ÷¹¤×÷ʱ¾ÍÊÇͨ¹ý¸Ä±äÕâ¸ö¼ÆÊýÆ÷µÄÖµÀ´Ñ¡È¡ÏÂÒ»ÌõÐèÒªÖ´ÐеÄ×Ö½ÚÂëÖ¸Á·ÖÖ§¡¢Ñ»·¡¢Òì³£´¦Àí¡¢Ïָ̻߳´µÈ»ù´¡¹¦Äܶ¼ÐèÒªÒÀÀµ¼ÆÊýÆ÷Íê³É¡£ 3.2.3 Ö±½ÓÄÚ´æ Ö±½ÓÄÚ´æ²¢²»ÊÇÐéÄâ»úÄÚ´æµÄÒ»²¿·Ö£¬Ò²²»ÊÇJavaÐéÄâ»ú¹æ·¶Öж¨ÒåµÄÄÚ´æÇøÓò¡£jdk1.4ÖÐмÓÈëµÄNIO£¬ÒýÈëÁËͨµÀÓ뻺³åÇøµÄIO·½Ê½£¬Ëü¿ÉÒÔµ÷ÓÃNative·½·¨Ö±½Ó·ÖÅä¶ÑÍâÄڴ棬Õâ¸ö¶ÑÍâÄÚ´æ¾ÍÊDZ¾»úÄڴ棬²»»áÓ°Ïìµ½¶ÑÄÚ´æµÄ´óС¡£ 3.2.4 JVM ÄÚ´æ·ÖÎö ²é¿´ JVM ¶ÑÄÚ´æÇé¿ö jmap -heap [pid]
¹ØÓÚÕâÀïµÄ¼¸¸ögenerationÍøÉÏ×ÊÁÏÒ»´ó°Ñ¾Í²»Ï¸ËµÁË£¬ÕâÀïËãÒ»ÏÂÇóºÍ¿ÉÒÔµÃ֪ǰÕß×ܹ²¸øJava»·¾³·ÖÅäÁË644MµÄÄڴ棬¶øpsÊä³öµÄVSZºÍRSS·Ö±ðÊÇ7.4GºÍ2.9G£¬Õâµ½µ×ÊÇÔõô»ØÊÂÄØ£¿ Ç°ÃæjmapÊä³öµÄÄÚÈÝÀMaxHeapSize ÊÇÔÚÃüÁîÐÐÉÏÅäµÄ£¬-Xmx4096m£¬Õâ¸öjava³ÌÐò¿ÉÒÔÓõ½µÄ×î´ó¶ÑÄÚ´æ¡£ VSZÊÇÖ¸ÒÑ·ÖÅäµÄÏßÐÔ¿Õ¼ä´óС£¬Õâ¸ö´óСͨ³£²¢²»µÈÓÚ³ÌÐòʵ¼ÊÓõ½µÄÄÚ´æ´óС£¬²úÉúÕâ¸öµÄ¿ÉÄÜÐԺܶ࣬±ÈÈçÄÚ´æÓ³É䣬¹²ÏíµÄ¶¯Ì¬¿â£¬»òÕßÏòϵͳÉêÇëÁ˸ü¶àµÄ¶Ñ£¬¶¼»áÀ©Õ¹ÏßÐÔ¿Õ¼ä´óС£¬Òª²é¿´Ò»¸ö½ø³ÌÓÐÄÄЩÄÚ´æÓ³É䣬¿ÉÒÔʹÓà pmap ÃüÁîÀ´²é¿´£º pmap -x [pid]
ÕâÀï¿ÉÒÔ¿´µ½ºÜ¶àanon£¬ÕâЩ±íʾÕâ¿éÄÚ´æÊÇÓÉmmap·ÖÅäµÄ¡£ RSZÊÇResident Set Size£¬³£×¤ÄÚ´æ´óС£¬¼´½ø³Ìʵ¼ÊÕ¼ÓõÄÎïÀíÄÚ´æ´óС£¬ ÔÚÏÖÔÚÕâ¸öÀý×Óµ±ÖУ¬RSZºÍʵ¼Ê¶ÑÄÚ´æÕ¼ÓòîÁË2.3G£¬Õâ2.3GµÄÄÚ´æ×é³É·Ö±ðΪ£º ²é¿´ JVM ¶Ñ¸÷¸ö·ÖÇøµÄÄÚ´æÇé¿ö jstat -gcutil [pid]
·ÖÎö JVM ¶ÑÄÚ´æÖеĶÔÏó ²é¿´´æ»îµÄ¶ÔÏóͳ¼Æ jmap -histo:live [pid] dump ÄÚ´æ jmap -dump:format=b,file=heapDump [pid] È»ºóÓÃjhatÃüÁî¿ÉÒԲο´ jhat -port 5000 heapDump ÔÚä¯ÀÀÆ÷ÖзÃÎÊ£ºhttp://localhost:5000/ ²é¿´ÏêϸÐÅÏ¢ 4. ·þÎñÖ¸±ê 4.1 ÏìӦʱ¼ä(RT) ÏìӦʱ¼äÊÇָϵͳ¶ÔÇëÇó×÷³öÏìÓ¦µÄʱ¼ä¡£Ö±¹ÛÉÏ¿´£¬Õâ¸öÖ¸±êÓëÈ˶ÔÈí¼þÐÔÄܵÄÖ÷¹Û¸ÐÊÜÊǷdz£Ò»Öµģ¬ÒòΪËüÍêÕûµØ¼Ç¼ÁËÕû¸ö¼ÆËã»úϵͳ´¦ÀíÇëÇóµÄʱ¼ä¡£ ÓÉÓÚÒ»¸öϵͳͨ³£»áÌṩÐí¶à¹¦ÄÜ£¬¶ø²»Í¬¹¦ÄܵĴ¦ÀíÂ߼Ҳǧ²îÍò±ð£¬Òò¶ø²»Í¬¹¦ÄܵÄÏìӦʱ¼äÒ²²»¾¡Ïàͬ£¬ÉõÖÁͬһ¹¦ÄÜÔÚ²»Í¬ÊäÈëÊý¾ÝµÄÇé¿öÏÂÏìӦʱ¼äÒ²²»Ïàͬ¡£ ËùÒÔ£¬ÔÚÌÖÂÛÒ»¸öϵͳµÄÏìӦʱ¼äʱ£¬ÈËÃÇͨ³£ÊÇÖ¸¸ÃϵͳËùÓй¦ÄܵÄƽ¾ùʱ¼ä»òÕßËùÓй¦ÄܵÄ×î´óÏìӦʱ¼ä¡£ µ±È»£¬ÍùÍùÒ²ÐèÒª¶Ôÿ¸ö»òÿ×鹦ÄÜÌÖÂÛÆäƽ¾ùÏìӦʱ¼äºÍ×î´óÏìӦʱ¼ä¡£ ¶ÔÓÚµ¥»úµÄûÓв¢·¢²Ù×÷µÄÓ¦ÓÃϵͳ¶øÑÔ£¬ÈËÃÇÆÕ±éÈÏΪÏìӦʱ¼äÊÇÒ»¸öºÏÀíÇÒ׼ȷµÄÐÔÄÜÖ¸±ê¡£ÐèÒªÖ¸³öµÄÊÇ£¬ÏìӦʱ¼äµÄ¾ø¶ÔÖµ²¢²»ÄÜÖ±½Ó·´Ó³Èí¼þµÄÐÔÄܵĸߵͣ¬Èí¼þÐÔÄܵĸߵÍʵ¼ÊÉÏÈ¡¾öÓÚÓû§¶Ô¸ÃÏìӦʱ¼äµÄ½ÓÊ̶ܳȡ£ ¶ÔÓÚÒ»¸öÓÎÏ·Èí¼þÀ´Ëµ£¬ÏìӦʱ¼äСÓÚ100ºÁÃëÓ¦¸ÃÊDz»´íµÄ£¬ÏìӦʱ¼äÔÚ1Ãë×óÓÒ¿ÉÄÜÊôÓÚÃãÇ¿¿ÉÒÔ½ÓÊÜ£¬Èç¹ûÏìӦʱ¼ä´ïµ½3Ãë¾ÍÍêÈ«ÄÑÒÔ½ÓÊÜÁË¡£ ¶ø¶ÔÓÚ±àÒëϵͳÀ´Ëµ£¬ÍêÕû±àÒëÒ»¸ö½Ï´ó¹æÄ£Èí¼þµÄÔ´´úÂë¿ÉÄÜÐèÒª¼¸Ê®·ÖÖÓÉõÖÁ¸ü³¤Ê±¼ä£¬µ«ÕâЩÏìӦʱ¼ä¶ÔÓÚÓû§À´Ëµ¶¼ÊÇ¿ÉÒÔ½ÓÊܵġ£ 4.2 ÍÌÍÂÁ¿(Throughput) ÍÌÍÂÁ¿ÊÇָϵͳÔÚµ¥Î»Ê±¼äÄÚ´¦ÀíÇëÇóµÄÊýÁ¿¡£¶ÔÓÚÎÞ²¢·¢µÄÓ¦ÓÃϵͳ¶øÑÔ£¬ÍÌÍÂÁ¿ÓëÏìӦʱ¼ä³ÉÑϸñµÄ·´±È¹Øϵ£¬Êµ¼ÊÉÏ´ËʱÍÌÍÂÁ¿¾ÍÊÇÏìӦʱ¼äµÄµ¹Êý¡£ Ç°ÃæÒѾ˵¹ý£¬¶ÔÓÚµ¥Óû§µÄϵͳ£¬ÏìӦʱ¼ä£¨»òÕßϵͳÏìӦʱ¼äºÍÓ¦ÓÃÑÓ³Ùʱ¼ä£©¿ÉÒԺܺõضÈÁ¿ÏµÍ³µÄÐÔÄÜ£¬µ«¶ÔÓÚ²¢·¢ÏµÍ³£¬Í¨³£ÐèÒªÓÃÍÌÍÂÁ¿×÷ΪÐÔÄÜÖ¸±ê¡£ ¶ÔÓÚÒ»¸ö¶àÓû§µÄϵͳ£¬Èç¹ûÖ»ÓÐÒ»¸öÓû§Ê¹ÓÃʱϵͳµÄƽ¾ùÏìӦʱ¼äÊÇt£¬µ±ÓÐÄãn¸öÓû§Ê¹ÓÃʱ£¬Ã¿¸öÓû§¿´µ½µÄÏìӦʱ¼äͨ³£²¢²»ÊÇn×t£¬¶øÍùÍù±Èn×tСºÜ¶à£¨µ±È»£¬ÔÚijЩÌØÊâÇé¿öÏÂÒ²¿ÉÄܱÈn×t´ó£¬ÉõÖÁ´óºÜ¶à£©¡£ ÕâÊÇÒòΪ´¦Àíÿ¸öÇëÇóÐèÒªÓõ½ºÜ¶à×ÊÔ´£¬ÓÉÓÚÿ¸öÇëÇóµÄ´¦Àí¹ý³ÌÖÐÓÐÐí¶à²»×ßÄÑÒÔ²¢·¢Ö´ÐУ¬Õâµ¼ÖÂÔÚ¾ßÌåµÄÒ»¸öʱ¼äµã£¬ËùÕ¼×ÊÔ´ÍùÍù²¢²»¶à¡£Ò²¾ÍÊÇ˵ÔÚ´¦Àíµ¥¸öÇëÇóʱ£¬ÔÚÿ¸öʱ¼äµã¶¼¿ÉÄÜÓÐÐí¶à×ÊÔ´±»ÏÐÖ㬵±´¦Àí¶à¸öÇëÇóʱ£¬Èç¹û×ÊÔ´ÅäÖúÏÀí£¬Ã¿¸öÓû§¿´µ½µÄƽ¾ùÏìӦʱ¼ä²¢²»ËæÓû§ÊýµÄÔö¼Ó¶øÏßÐÔÔö¼Ó¡£ ʵ¼ÊÉÏ£¬²»Í¬ÏµÍ³µÄƽ¾ùÏìӦʱ¼äËæÓû§ÊýÔö¼Ó¶øÔö³¤µÄËÙ¶ÈÒ²²»´óÏàͬ£¬ÕâÒ²ÊDzÉÓÃÍÌÍÂÁ¿À´¶ÈÁ¿²¢·¢ÏµÍ³µÄÐÔÄܵÄÖ÷ÒªÔÒò¡£ Ò»°ã¶øÑÔ£¬ÍÌÍÂÁ¿ÊÇÒ»¸ö±È½ÏͨÓõÄÖ¸±ê£¬Á½¸ö¾ßÓв»Í¬Óû§ÊýºÍÓû§Ê¹ÓÃģʽµÄϵͳ£¬Èç¹ûÆä×î´óÍÌÍÂÁ¿»ù±¾Ò»Ö£¬Ôò¿ÉÒÔÅжÏÁ½¸öϵͳµÄ´¦ÀíÄÜÁ¦»ù±¾Ò»Ö¡£ 4.3 ²¢·¢Óû§Êý ²¢·¢Óû§ÊýÊÇָϵͳ¿ÉÒÔͬʱ³ÐÔصÄÕý³£Ê¹ÓÃϵͳ¹¦ÄܵÄÓû§µÄÊýÁ¿¡£ÓëÍÌÍÂÁ¿Ïà±È£¬²¢·¢Óû§ÊýÊÇÒ»¸ö¸üÖ±¹Ûµ«Ò²¸üÁýͳµÄÐÔÄÜÖ¸±ê¡£ ʵ¼ÊÉÏ£¬²¢·¢Óû§ÊýÊÇÒ»¸ö·Ç³£²»×¼È·µÄÖ¸±ê£¬ÒòΪÓû§²»Í¬µÄʹÓÃģʽ»áµ¼Ö²»Í¬Óû§ÔÚµ¥Î»Ê±¼ä·¢³ö²»Í¬ÊýÁ¿µÄÇëÇó¡£ Ò»ÍøվϵͳΪÀý£¬¼ÙÉèÓû§Ö»ÓÐ×¢²áºó²ÅÄÜʹÓ㬵«×¢²áÓû§²¢²»ÊÇÿʱÿ¿Ì¶¼ÔÚʹÓøÃÍøÕ¾£¬Òò´Ë¾ßÌåÒ»¸öʱ¿ÌÖ»Óв¿·Ö×¢²áÓû§Í¬Ê±ÔÚÏߣ¬ÔÚÏßÓû§¾ÍÔÚä¯ÀÀÍøվʱ»á»¨ºÜ¶àʱ¼äÔĶÁÍøÕ¾ÉϵÄÐÅÏ¢£¬Òò¶ø¾ßÌåÒ»¸öʱ¿ÌÖ»Óв¿·ÖÔÚÏßÓû§Í¬Ê±Ïòϵͳ·¢³öÇëÇó¡£ ÕâÑù£¬¶ÔÓÚÍøվϵͳÎÒÃÇ»áÓÐÈý¸ö¹ØÓÚÓû§ÊýµÄͳ¼ÆÊý×Ö£º×¢²áÓû§Êý¡¢ÔÚÏßÓû§ÊýºÍͬʱ·¢ÇëÇóÓû§Êý¡£ÓÉÓÚ×¢²áÓû§¿ÉÄܳ¤Ê±¼ä²»µÇ½ÍøÕ¾£¬Ê¹ÓÃ×¢²áÓû§Êý×÷ΪÐÔÄÜÖ¸±ê»áÔì³ÉºÜ´óµÄÎó²î¡£¶øÔÚÏßÓû§ÊýºÍͬÊ·¢ÇëÇóÓû§Êý¶¼¿ÉÒÔ×÷ΪÐÔÄÜÖ¸±ê¡£ Ïà±È¶øÑÔ£¬ÒÔÔÚÏßÓû§×÷ΪÐÔÄÜÖ¸±ê¸üÖ±¹ÛЩ£¬¶øÒÔͬʱ·¢ÇëÇóÓû§Êý×÷ΪÐÔÄÜÖ¸±ê¸ü׼ȷЩ¡£ 4.4 QPSÿÃë²éѯÂÊ(Query Per Second) ÿÃë²éѯÂÊQPSÊǶÔÒ»¸öÌض¨µÄ²éѯ·þÎñÆ÷Ôڹ涨ʱ¼äÄÚËù´¦ÀíÁ÷Á¿¶àÉٵĺâÁ¿±ê×¼£¬ÔÚÒòÌØÍøÉÏ£¬×÷ΪÓòÃûϵͳ·þÎñÆ÷µÄ»úÆ÷µÄÐÔÄܾ³£ÓÃÿÃë²éѯÂÊÀ´ºâÁ¿¡£¶ÔÓ¦fetches/sec£¬¼´Ã¿ÃëµÄÏìÓ¦ÇëÇóÊý£¬Ò²¼´ÊÇ×î´óÍÌÍÂÄÜÁ¦¡£ ´ÓÒÔÉϸÅÄîÀ´¿´ÍÌÍÂÁ¿ºÍÏìӦʱ¼äÊǺâÁ¿ÏµÍ³ÐÔÄܵÄÖØÒªÖ¸±ê£¬QPSËäÈ»ºÍÍÌÍÂÁ¿µÄ¼ÆÁ¿µ¥Î»²»Í¬£¬µ«Ó¦¸ÃÊdzÉÕý±ÈµÄ£¬ÈκÎÒ»¸öÖ¸±ê¶¼¿ÉÒÔº¬Á¿·þÎñÆ÷µÄ²¢Ðд¦ÀíÄÜÁ¦¡£µ±È»Throughput¸ü¹ØÐÄÊý¾ÝÁ¿£¬QPS¸ü¹ØÐÄ´¦Àí±ÊÊý¡£ 4.5 CPUÀûÓÃÂÊ CPU Load Average < CPU¸öÊý ºËÊý 0.7 Context Switch Rate ¾ÍÊÇProcess£¨Thread£©µÄÇл»£¬Èç¹ûÇл»¹ý¶à£¬»áÈÃCPUæÓÚÇл»£¬Ò²»áµ¼ÖÂÓ°ÏìÍÌÍÂÁ¿¡£ ¡¶¸ßÐÔÄÜ·þÎñÆ÷¼Ü¹¹ ¡·ÕâƪÎÄÕµĵÚ2½Ú¾ÍÊÇ˵µÄÊÇÕâ¸öÎÊÌâµÄ¡£ ¾¿¾¹¶àÉÙËãºÏÊÊ£¿google ÁËÒ»´óȦ£¬Ã»ÓÐÒ»¸öÈ·ÇеĽâÊÍ¡£ Context Switch´óÌåÉÏÓÉÁ½¸ö²¿·Ö×é³É£ºÖжϺͽø³Ì(°üÀ¨Ïß³Ì)Çл»£¬Ò»´ÎÖжϣ¨Interrupt£©»áÒýÆðÒ»´ÎÇл»£¬½ø³Ì£¨Ị̈߳©µÄ´´½¨¡¢¼¤»îÖ®ÀàµÄÒ²»áÒýÆðÒ»´ÎÇл»¡£CSµÄÖµÒ²ºÍTPS£¨Transaction Per Second£©Ïà¹ØµÄ£¬¼ÙÉèÿ´Îµ÷ÓûáÒýÆðN´ÎCS£¬ÄÇô¾Í¿ÉÒԵóö Context Switch Rate = Interrupt Rate + TPS* N CSR¼õµôIR£¬¾ÍÊǽø³Ì/Ï̵߳ÄÇл»£¬¼ÙÈçÖ÷½ø³ÌÊÕµ½ÇëÇ󽻸øÏ̴߳¦Àí£¬Ï̴߳¦ÀíÍê±Ï¹é»¹¸øÖ÷½ø³Ì£¬ÕâÀï¾ÍÊÇ2´ÎÇл»¡£ Ò²¿ÉÒÔÓÃCSR¡¢IR¡¢TPSµÄÖµ´úÈ빫ʽÖУ¬µÃ³öÿ´ÎÊÂÎïµ¼ÖµÄÇл»Êý¡£Òò´Ë£¬Òª½µµÍCSR£¬¾Í±ØÐëÔÚÿ¸öTPSÒýÆðµÄÇл»ÉÏϹ¦·ò£¬Ö»ÓÐNÕâ¸öÖµ½µÏÂÈ¥£¬CSR¾ÍÄܽµµÍ£¬ÀíÏëÇé¿öÏÂN=0£¬µ«ÊÇÎÞÂÛÈçºÎÈç¹ûN >= 4£¬ÔòÒªºÃºÃ¼ì²é¼ì²é¡£ÁíÍâÍøÉÏ˵µÄCSR<5000£¬ÎÒÈÏΪ±ê×¼²»¸ÃÈç´Ëµ¥Ò»¡£ ÕâÈý¸öÖ¸±êÔÚ LoadRunner ÖпÉÒÔ¼à¿Øµ½£»ÁíÍ⣬ÔÚ linux ÖУ¬Ò²¿ÉÒÔÓà vmstat ²é¿´r£¨Load Arerage£©£¬in£¨Interrupt£©ºÍcs£¨Context Switch£© 5. ¹¤¾ß uptime dmesg top ²é¿´½ø³Ì»î¶¯×´Ì¬ÒÔ¼°Ò»Ð©ÏµÍ³×´¿ö vmstat ²é¿´ÏµÍ³×´Ì¬¡¢Ó²¼þºÍϵͳÐÅÏ¢µÈ iostat ²é¿´CPU ¸ºÔØ£¬Ó²ÅÌ×´¿ö sar ×ۺϹ¤¾ß£¬²é¿´ÏµÍ³×´¿ö mpstat ²é¿´¶à´¦ÀíÆ÷×´¿ö netstat ²é¿´ÍøÂç×´¿ö iptraf ʵʱÍøÂç×´¿ö¼à²â tcpdump ץȡÍøÂçÊý¾Ý°ü£¬Ïêϸ·ÖÎö mpstat ²é¿´¶à´¦ÀíÆ÷×´¿ö tcptrace Êý¾Ý°ü·ÖÎö¹¤¾ß netperf ÍøÂç´ø¿í¹¤¾ß dstat ×ۺϹ¤¾ß£¬×ÛºÏÁË vmstat, iostat, ifstat, netstat µÈ¶à¸öÐÅÏ¢ £¨±à¼£ºASPÕ¾³¤Íø£© |