暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

为什么Mysql使用多线程,而Oracle和 PostgreSQL使用多进程?

小谢backup 2018-01-27
866

传统的Unix系统早期没有提供多线程,只有多进程。Linux是最近的版本才加入多线程支持,以前一直都是多进程。windows很早就支持多线程,本地应用大部分也是多线程。因此oracle在windows上一直都是多线程,在unix上才是多进程。

多进程的好处是,一个进程崩溃不会影响其他进程,多线程的好处是不需要共享内存这样的手段来访问数据库缓冲区。 诸如Oracle这种商业数据库,基本都支持多种Process Models, Oracle默认是多进程。 多线程多进程在Linux的差别不是很大,但是在Windows的性能差别就比较大,实际上Oracle在Windows的版本也是多线程的。多线程的好处就是相对来将稳定性较好,一个进程挂掉,重新拉起来就好,但是一个线程crash会导致整个进程都crash掉的。 根据Understanding MySQL Internals所说, MySQL一开始是Solaris上的 :

Thus in May of 1996 MySQL version 1.0 was released to a limited group, followed by a public release in October 1996 of version 3.11.1. The initial public release provided only a binary distribution for Solaris. A month later, the source and the Linux binary were released. 这本书也提及了,为什么MySQL用多线程: Just as a good rider becomes one with the horse, Monty(MySQL author) had become one with the computer. It pained him to see system resources wasted. He felt confident enough to be able to write virtually bug-free code, deal with the concurrency issues presented by threads, and even work with s small stack. What an exciting challenge! Needless to say, he chose threads.

Postgres的原因可以在The design of Postgres中找到:

However, this approach requires that a fairly complete special-purpose operating system be built. In contrast, the process-per-user model is simpler to implement but will not perform as well on most conventional operating systems. We decided after much soul searching to implement POSTGRES using a process-per-user model architecture because of our limited programming resources.

总而言之,最根本的原因是当年操作系统对线程支持不给力,而MySQL是特例,因为开发者喜欢挑战(不过事实上,那个时候的线程支持已经基本完善了。MySQL后于Oracle和POSTGRES). 网上一个外国大牛直接的回答:

   windows is an os that prefers threads. 
  linux is not. 
  we do threads on windows. 
  we do processes on unix 
  we do whatever the underlying os "likes"
复制


文章转载自小谢backup,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论