PDA

View Full Version : thread and processes - difference?


sir pannels
08-06-2009, 02:50 PM
hello there

im trouble shooting some problems with the performance of a website that is a having some issues and I'm currently at the mysql point of my invesigation. A few questions have arisen.

What is the difference between threads and processes? It seems everytime a query is ran on the mysql server, the thread count goes up 1. When it ends, thread count goes down 1. Are threads the same as processes?

There is always one more thread than their are processes running under show processlist.

Additionally, if I show the status of mysql I get 4 variations of threads...
| Threads_cached | 0 |
| Threads_connected | 2 |
| Threads_created | 43 |
| Threads_running | 1 |


Any assistance with working out what exactly the difference between the difference thread types and also processes are then that would be excellent.

Cheers,

sir pannels
08-06-2009, 03:11 PM
I think I may have the answer to half my question...

My guess is ... When mysql starts on a server, that is thread 1.... then for each new connection that connects to the mysql server a new thread is created. All queries done from that connection are then under that 1 thread... I think that is how it works...

If it is how it should work, then I have found my problem... not the resolution though.... got a website that will sit 'loading' with a blank screen for.. 15 minutes... if you look at status of mysql, a sleep process is running from your last action... if you refresh the page you get a new sleep process under a new thread... if i open up a totally different browser on the same PC and try the same page, a new thread opens, query runs and ends (no sleep process) and then the thread closes ... website loads fine in the browser..... yet original browser is still 'loading'.......

Does this sound familar to anyone?

Old Pedant
08-06-2009, 08:57 PM
Your analysis looks fine.

But no idea why MySQL would sleep based on one query but then not sleep on an identical (or is it?) one.

Oh...and a process is, essentially, an executable program. Each program can have multiple threads. Each program (typically! there can be exceptions, depending on the operating system in use!) uses only a single process.

On modern machines, each process runs in its own memory space. That is, mysql might be using address 0x221777 at the same time that the Apache web server is using address 0x221777 and there is no conflict. The processes are "isolated" from each other. Not so with threads: It is the responsibility of the process (that is, the program) to make sure that the threads don't step on each other's toes. Fortunately, modern computer languages and operating systems make it not too terribly hard to write multi-threaded code. But, still, multi-threaded code is not for the faint of heart.