理解Global interpreter lock
Global interpreter lock (GIL) is a mechanism used in computer language interpreters to synchronize the execution of
threads so that only one native thread can execute at a time. An interpreter that uses GIL always allows exactly one
thread to execute at a time, even if run on a multi-core processor.
Benefits and drawbacks
increased speed of single-threaded programs (no necessity to acquire or release locks on all data structures separately)
2. easy integration of C libraries that usually are not thread-safe
3. ease of implementation (having a single GIL is much simpler to implement than a lock-free interpreter or one using fine-grained locks).
Use of a global interpreter lock in a language effectively limits the amount of parallelism reachable through concurrency of a
single interpreter process with multiple threads. If the process is almost purely made up of interpreted code and does not
make calls outside of the interpreter for long periods of time (which can release the lock on the GIL on that thread while it
processes), there is likely to be very little increase in speed when running the process on a multiprocessor machine. Due to
signaling with a CPU-bound thread, it can cause a significant slowdown, even on single processors.
原因在于,Tornado采用的的单进程单线程异步IO的网络模型。Python虽然有多线程,但是Python的解释器有GIL这点非常影响了Python
利用多核的能力,所以只能通过多进程来利用多核。既然多进程,一般就需要在前端放置nginx做为负载均衡的反向代理,或是使用这些应
用服务器的wsgi模块来管理进程的生命周期 。
对于含有IO阻塞的环境,比如网络通讯、磁盘读写, 当发生阻塞时,CPU是闲置的,此时如果就一个线程就没法处理其他事情了。
所以多线程可以提高CPU利用率。
理解Global interpreter lock的更多相关文章
- python之GIL(Global Interpreter Lock)
一 介绍 ''' 定义: In CPython, the global interpreter lock, or GIL, is a mutex that prevents multiple nati ...
- **解释器全局锁(Global Interpreter Lock)
解释器全局锁(Global Interpreter Lock),即Python为了保证线程安全而采取的独立线程运行的限制,说白了就是一个核只能在同一时间运行一个线程. [解决办法就是多进程和协程(协程 ...
- Python GIL(Global Interpreter Lock)
一,介绍 定义: In CPython, the global interpreter lock, or GIL, is a mutex that prevents multiple native t ...
- Python3 GIL(Global Interpreter Lock)与多线程
GIL(Global Interpreter Lock)与多线程 GIL介绍 GIL与Lock GIL与多线程 多线程性能测试 在Cpython解释器中,同一个进程下开启的多线程,同一时刻只能有一个线 ...
- python之GIL官方文档 global interpreter lock 全局解释器锁
0.目录 2. 术语 global interpreter lock 全局解释器锁3. C-API 还有更多没有仔细看4. 定期切换线程5. wiki.python6. python.doc FAQ ...
- Python GIL(Global Interpreter Lock)
一.介绍 In CPython, the global interpreter lock, or GIL, is a mutex that prevents multiple native threa ...
- python GIL(Global Interpreter Lock)
一 介绍 ''' 定义: In CPython, the global interpreter lock, or GIL, is a mutex that prevents multiple nati ...
- 基于Cpython的 GIL(Global Interpreter Lock)
一 介绍 定义: In CPython, the global interpreter lock, or GIL, is a mutex that prevents multiple native t ...
- Python解释器是单线程应用 IO 密集型 计算密集型 GIL global interpreter lock
[Python解释器是单线程应用] [任意时刻,仅执行一个线程] 尽管Python解释器中可以运行多个线程,但是在任意给定的时刻只有一个线程会被解释器执行. [GIL锁 保证同时只有一个线程运行] 对 ...
随机推荐
- 专题实验 Toad 用户的创建与管理( 包括 role 等 )
1. 用户登录数据库 是否可以通过操作系统权限来登录数据库, $ORACLE_HOME/network/admin/sqlnet.ora 这个文件中设置, 如果增加参数sqlnet.authentic ...
- python文件编码说明 coding=utf-8
python 支持3种编码声明,一般常用能见到下面两种 1.# -*- coding: utf-8 -*- 这种写法是为了兼容Emacs的编码声明 2.短一点,但Emacs不能用# coding=ut ...
- windows下端口占用解决方法-查看和杀死占用端口进程
在Windows下启动程序时有时会遇到端口被占用的情况,由于一个端口同时只能运行一个进程,所以要想启动新的程序就要先把占用该端口的进程给kill掉,具体的命令分为以下三步, 以杀死占用了80端口的进程 ...
- 树形dp - BNU 39572 Usoperanto
Usoperanto Problem's Link Mean: 给定n个单词,每个单词可以作为形容词来修饰其他单词. 如果当前单词Wi修饰Wj,那么这个修饰的代价是:Wi~Wj之间的单词的总长度. 你 ...
- php if语句判定my查询是否为空
<?php header("Content-type: text/html; charset=utf-8"); $username=$_GET['username']; $p ...
- Thymeleaf 3.0.9.RELEASE is the current stable version. It requires Java SE 6 or newer.
Thymeleaf 3.0.9.RELEASE is the current stable version. It requires Java SE 6 or newer. Release date: ...
- (转自)视频流中的DTS/PTS到底是什么;
翻译了一下: Q:hi,这可能是一个弱智问题,但是当我使用bbMEG1.24beta17编码时,一直以来总是遇到这个下溢的问题.我从日志文件中得到的唯一启示就是我应该更改mux率...但是帮助文档却 ...
- sublime text 2安装Emment插件
写个自己看的 1. 命令行模式 ctrl+` 可以调出命令行模式(view->show console),主要支持python语法等,没试用过只知 quit()可以退出 ..不过sublime的 ...
- [转] 关于EJB分析
转自:http://blog.csdn.net/jojo52013145/article/details/5783677 1. 我们不禁要问.什么是"服务集群"?什么是" ...
- [NOIP 2014复习]第二章:搜索
一.深度优先搜索(DFS) 1.Wikioi 1066引水入城 题目描写叙述 Description 在一个遥远的国度,一側是风景秀美的湖泊,还有一側则是漫无边际的沙漠.该国的行政 区划十分特殊,刚好 ...