Note: This document only applies to DiscuzNT3.0 and sqlserver 2000 versions. Do not use the check boxes for other versions.
In article (4) of this series, we mentioned windbg. He was not able to make a big debut last time. Today, he finally has to show his talents. Solving the problem is inherent in windbg. How will he solve our problem today.
After the optimization in article (4), our forum ushered in a breakthrough of 1 million pv every day. Compared with other projects, this volume is not worth mentioning, but after all, this project starts from scratch. It is a small breakthrough to achieve this amount. It is worth celebrating. However, the problem also arises. The cpu usage of our iis server has increased from about 30% to 80%. According to our experience, this is unreasonable. 80% is already a dangerous signal, server too busy may be triggered at any time.
From the perspective of the company's interests, in order to save server resources and costs, of course, the cpu should be reduced; from the perspective of technical personnel, if you have not solved the problem before, this will be a challenge to yourself. If you solve it, it will be just the embodiment of your value. This is the same as the so-called hero in the world. All right, let's talk a little bit about it. Please visit windbg, the star of today.
I will not talk about windbg any more. I only published my two points of understanding about him, which is quite popular:
1) The Memory package can be captured, that is, the dump file;
2) output the actions being executed in the memory using commands;
3rd) Step 1 is what the technicians themselves need to do. analyze and find out the crux of the problem through command output information. In this step, windbg cannot help you.
The most common problem that windbg solves on the internet is
1) program crash;
2) program suspension, such as deadlock and timeout;
3) high cpu;
4) Memory leakage;
Let's take a look at how he found it today. 3) high cpu problems.
The common methods and steps for windbg to locate high cpu usage are as follows:
1) capture a package at a high cpu interval of about 5 seconds and 3 or so. Run the adplus command;
2) pass! Run the runaway command to find the first few threads of each package (about 10 );
3) then find the thread id that appears in the first 10 threads each time;
4) pass! Clrstack name outputs the execution action of the thread;
5) Identify the crux of the problem through 4th) output information.
(I think this is a vague description of many articles on the Internet );
5th). I want to give my opinion on what these thread IDs are doing. If eight of them stay in one method, this method is very doubtful and requires a key check. Let's take a look at the dnt3.0 situation step by step.
1) Capture packets first. Capture 3 packets by using adplus in cmd at an interval of 10 seconds (the usage of the windbg command is not the focus of this Article. google can have a basket );
2) use windbg to open three dump files and run them! Runaway command to find the time-consuming thread;
The three files are as follows:
1st sheets
2nd sheets
3rd sheets
3) find 10 most time-consuming threads.
4) pass! Clrstack command output what they are doing (because there are too many, here only a few representative)
Thread 11:
----------------
0: 000> ~ 11 s
Eax = 02d25354 ebx = 001410a8 ecx = 02d253ec edx = 02d2541c esi = 00000360 edi = 00000000eip = 7c95847c esp = 020bf15c ebp = 020bf1cc iopl = 0 nv up ei pl zr na pe nccs = 001b = 0023 ds = 0023 es = 0023 fs = 003b gs = 0000 efl = 00000246 ntdll! KiFastSystemCallRet: 7c95847c c3 ret0: 011>! ClrstackOS Thread Id: 0x143c (11) esp eip 020bf2cc 7c95847c [GCFrame: 020bf2cc] 1097c95847c [HijackFrame: 020bf2e8] 020bf32c 69c7bc58 System. xml. xmlElement. get_XPLocalName () 020bf330 69c6ea0d System. xml. documentXPathNavigator. get_LocalName () 020bf334 69ca30c5 MS. internal. xml. XPath. XPathAxisIterator. get_Matches () 020bf344 69ca37a8 MS. internal. xml. XPath. XPathChildIterator. moveNext () 020bf34c 69c99ce1 MS. internal. xml. XPath. childrenQuery. advance () 020bf35c 69ca6fcc MS. internal. xml. XPath. XPathSelectionIterator. moveNext () 020bf368 69c83b07 System. xml. XPathNodeList. readUntil (Int32) 020bf378 69c83ac1 System. xml. XPathNodeList. get_Count () 020bf380 69c72736 System. xml. xmlNode. selectSingleNode (System. string) 020bf390 1b9ebe3f Discuz. cache. DNTCache. retrieveOriginObject (System. string) 020bf398 1b9ebde3 Discuz. cache. DNTCache. retrieveObject (System. string) 020bf3c4 1b9ee906 Discuz. forum. userGroups. getUserGroupList () 020bf3d0 1b9ee853 Discuz. forum. userGroups. getUserGroupInfo (Int32) 020bf3e0 1b9ea7dc Discuz. forum. pageBase .. ctor () 020bf484 1b9e9e60 Discuz. web. UI. avatar .. ctor () 020bf490 1b9e9deb ASP. tools_avatar_aspx .. ctor () 020bf498 1b9e9dc5 _ ASP. fastObjectFactory_app_web_idnpx4j6.Create_ASP_tools_avatar_aspx ()
...... A few words are omitted here.
---------------------------
Thread 12:
----------
0: 012>! ClrstackOS Thread Id: 0x10d0 (12) esp eip 0213f3b4 7c95847c [HijackFrame: 0213f3b4] 0213f3f4 69c6f8be System. xml. documentXPathNavigator. moveToNext () 0213f404 69ca37c8 MS. internal. xml. XPath. XPathChildIterator. moveNext () 0213f40c 69c99ce1 MS. internal. xml. XPath. childrenQuery. advance () 0213f41c 69ca6fcc MS. internal. xml. XPath. XPathSelectionIterator. moveNext () 0213f428 69c83b07 System. xml. XPathNodeList. readUntil (Int32) 0213f438 69c83ac1 System. xml. XPathNodeList. get_Count () 0213f440 69c72736 System. xml. xmlNode. selectSingleNode (System. string) 0213f450 1b9ebe3f Discuz. cache. DNTCache. retrieveOriginObject (System. string) 0213f458 1b9ebde3 Discuz. cache. DNTCache. retrieveObject (System. string) 0213f484 1c8d2242 Discuz. forum. templates. getValidTemplateList () 0213f4b8 1c8d2020 Discuz. forum. templates. getTemplateItem (Int32) 0213f4d4 1b9ea9c2 Discuz. forum. pageBase .. ctor () 0213f578 1b9efa4a Discuz. web. UI. topicPage .. ctor () 0213f584 1b9ef8ca Discuz. web. showtopic .. ctor () 0213f590 1b9ef7e3 ASP. aspx_2_showtopic_aspx .. ctor () 0213f598 1b9ef7bd _ ASP. fastObjectFactory_app_web_ompjorep.Create_ASP_aspx_2_showtopic_aspx ()
...... A few words are omitted here.
---------------------------
Thread 22:
--------
0: 022>! ClrstackOS Thread Id: 0x11e8 (22) esp eip 1c27f1f0 7c95847c [HijackFrame: 1c27f1f0] 1c27f230 69ca37c8 MS. internal. xml. XPath. XPathChildIterator. moveNext () 1c27f238 69c99ce1 MS. internal. xml. XPath. childrenQuery. advance () 1c27f248 69ca6fcc MS. internal. xml. XPath. XPathSelectionIterator. moveNext () 1c27f254 69c83b07 System. xml. XPathNodeList. readUntil (Int32) 1c27f264 69c83ac1 System. xml. XPathNodeList. get_Count () 1c27f26c 69c72736 System. xml. xmlNode. selectSingleNode (System. string) 1c27f27c 1b9ebe3f Discuz. cache. DNTCache. retrieveOriginObject (System. string) 1c27f284 1b9ebde3 Discuz. cache. DNTCache. retrieveObject (System. string) 1c27f2b0 1c8d2c7b Discuz. forum. onlineUsers. getOnlineAllUserCount () 1c27f2c4 1c8d1683 Discuz. forum. onlineUsers. getCacheOnlineAllUserCount () 1c27f2d4 1b9ea930 Discuz. forum. pageBase .. ctor () 1c27 F378 1b9efa4a Discuz. web. UI. topicPage .. ctor () 1c27f384 1b9ef8ca Discuz. web. showtopic .. ctor () 1c27f390 1b9ef7e3 ASP. aspx_2_showtopic_aspx .. ctor () 1c27f398 1b9ef7bd _ ASP. fastObjectFactory_app_web_ompjorep.Create_ASP_aspx_2_showtopic_aspx ()...... These two words are omitted.
---------------------------
Thread 48:
--------
0: 048>! ClrstackOS Thread Id: 0x1620 (48) esp eip 1f11eb54 7c95847c [HelperMethodFrame: 1f11eb54] 1f11ebac 79357d11 System. string. concatArray (System. string [], Int32) 1f11ebc0 79371853 System. string. concat (System. string []) 1f11ebd8 7a4aec86 System. text. regularExpressions. regex .. ctor (System. string, System. text. regularExpressions. regexOptions, Boolean) 1f11ec0c 7a4bf93a System. text. regularExpressions. regex. split (System. string, System. string, System. text. regularExpressions. regexOptions) 1f11ec20 1b9ed247 Discuz. common. utils. splitString (System. string, System. string) 1f11ec2c 1c8d1952 Discuz. common. utils. inIPArray (System. string, System. string []) 1f11ec48 1c8d1869 Discuz. forum. pageBase. validateUserPermission () 1f11ec54 1b9ea950 Discuz. forum. pageBase .. ctor () 1f11ecf8 1b9efa4a Discuz. web. UI. topicPage .. ctor () 1f11ed04 1b9ef8ca Discuz. Web. showtopic .. ctor () 1f11ed10 1b9ef7e3 ASP. ctor .. ctor () 1f11ed18 1b9ef7bd _ ASP. Digest ()...... A few words are omitted here.
---------------------------
Look at the above several threads, although the Code is not exactly the same, but there are several places that are the same. The red mark is that the above several threads are all executed
Discuz. cache. DNTCache. retrieveObject: similar to this Code, there are 6 of these 10 threads, which are not listed one by one. Two of them are not tracked for execution, the other two threads are doing other things (the above 48 is one of them). Now we only focus on these six threads, because they all execute
Discuz. Cache. DNTCache. RetrieveObject. I think there is a performance problem here. Let's take a look at his source code.
1 /// <summary>
2 // return data items in the specified XML Path
3 /// </summary>
4 // <param name = "xpath"> classification Object Path </param>
5 /// <returns> </returns>
6 public virtual object RetrieveOriginObject (string xpath)
7 {
8 if (applyMemCached)
9 {
10 // Add a new object to the cache
11 return cs. RetrieveObject (xpath );
12}
13 else
14 {
15 XmlNode node = objectXmlMap. SelectSingleNode (PrepareXpath (xpath ));
16 if (node! = Null)
17 {
18 string objectId = node. Attributes ["objectId"]. Value;
19
20 return cs. RetrieveObject (objectId );
21}
22 return null;
23}
24}
Let's take a look.
ObjectXmlMap. SelectSingleNode how is this implemented? Please refer to reflector
Public XmlNode SelectSingleNode (string xpath)
{
XmlNodeList list = this. SelectNodes (xpath );
If (list! = Null) & (list. Count> 0 ))
{
Return list [0];
}
Return null;
}
Check again
This. SelectNodes (xpath );
Public XmlNodeList SelectNodes (string xpath)
{
XPathNavigator navigator = this. CreateNavigator ();
If (navigator = null)
{
Return null;
}
Return new XPathNodeList (navigator. Select (xpath ));
}
It's complicated. Let's look at it again.
CreateNavigator
Public virtual XPathNavigator CreateNavigator ()
{
XmlDocument document = this as XmlDocument;
If (document! = Null)
{
Return document. CreateNavigator (this );
}
Return this. OwnerDocument. CreateNavigator (this );
}
Oh, I can see it here. SelectSingleNode finally gets the result through the following process:
Create XmlDocument -- create XPathNavigator -- get all Nodes -- return the first node
How much performance will be consumed by such a process? The testing method varies with each person, so the results may be different. You can test the interesting children's shoes by yourself, because I am not familiar with this caching scheme and cannot predict its performance, I had to change it to my own familiarity, and finally use the built-in HttpRuntime of the system. cache.
The effect of modifying the cache policy is good. The cpu usage has dropped from> 80% to <30%. Capture the figure below: