多线程开发¶
多线程开发中的一些注意事项:¶
假定有一个线程(进程)A, 多个线程(进程)B,A知道所有的B的状态,B之间相互不了 解
- 首先要注意到有多个B,它们执行的代码一样,如果对某一个资源进行读写,需要考 虑互斥
- 由于第1条说明的互斥问题,所以可以考虑把可能引起互斥的数据操作由A来完成然后 通知B
- 第2条中又引起了一个问题,因为B有多个,那么A应该通知哪个B呢?这里最为安全的 是在A中对B进行轮询,这个可以避免由于某个B突然失联引起问题,即使某个B线程( 进程)失联了,下次运行时,A就会通知另外一个B,从而避免了一直向失联的B向信 息
关于数据的设计¶
对于一类数据,最好由一个进程来管理,如果其它进程需要相应的数据,与数据管理进程 沟通,以获取数据,而不是直接去操作数据。
MySQL日志相关服务器变量¶
MySQL Server参数中与日志相关的选项。如:Error Log, General query log, Binary log, Relay log, Slow query log。
Nginx指令介绍¶
详细信息请查看Nginx 原文档(English[#ref1]_, 淘宝中文版[2])
Proxy_cache相关指令¶
proxy_cache¶
prox_cache zone_name | off;
为cache指定一个共享存储区。相同的存储区可以在不同的地方使用。如果设定为off可以关闭从上级配置中继承的cache定义。
共享存储区域”zone_name“是由指令proxy_cache_path定义的。
proxy_cache_path¶
proxy_cache_path path [levels=levels] keys_zone=name:size
[inactive=time] [max_size=size] [loader_files=number]
[loader_sleep=time] [loader_threshold=time];
设定缓存的存储路径和其他一些参数。被缓存的数据都存储在文件中。存储在缓存区的key和文件名是通过被代理的URL的MD5值处理后得到的。参数`levels`用于定义缓存的存放级别的。例如:下面的指令:
proxy_cache_path /data/nginx/cache *levels*=1:2 keys_zone=one:10m;
被缓存的文件在缓存区中是这样存放的:
/data/nginx/cache/c/29/b7f54b2df7773722d382f4809d650*29c*
A cached response is first written to a temporary file, then a file is renamed. Starting from version 0.8.9 temporary files and the cache can be put on different file systems but be aware that in this case a file is copied across two file systems instead of the cheap rename operation. It is thus recommended that for any given location both cache and a directory holding temporary files set by the proxy_temp_path directive are put on the same file system. 缓存的响应首先写入到一个临时文件,然后进行重命名。
In addition, all active keys and information about data are stored in a shared memory zone, whose name and size are configured by the keys_zone parameter. Cached data that are not accessed during the time specified by the inactive parameter get removed from the cache regardless of their freshness. By default, inactive is set to 10 minutes.
The special process “cache manager” monitors the maximum cache size set by the max_size parameter; when this size is exceeded it removes the least recently used data.
A minute after the start the special process “cache loader” is activated that loads information about previously cached data stored on file system into a cache zone. A load is done in iterations. During one iteration no more than loader_files items are loaded (by default, 100). Besides, the duration of one iteration is limited by the loader_threshold parameter (by default, 200 milliseconds). A pause is made between iterations, configured by the loader_sleep parameter (by default, 50 milliseconds).
proxy_cache_bypass¶
proxy_cache_bypass string ...;
定义在哪些情况下,响应数据不从缓存中取得。当至少有一个字符参数不为空(“”)且不等于”0”,响应就不会从缓存中提取。
proxy_cache_bypass的功能与下面的proxy_no_cache相同。
proxy_cache_key¶
proxy_cacke_key $scheme$proxy_host$request_uri;
proxy_cache_valid¶
proxy_cache_valid 200 302 10m;
proxy_cache_valid 404 1m;
proxy_cache_valid any 1m;
proxy_cache_lock¶
proxy_cache_lock on | off
proxy_cache_lock_timeout¶
proxy_cache_lock_timeout 5s
proxy_cache_min_uses¶
proxy_cache_min_uses 1;
proxy_cache_use_stale¶
proxy_cache_use_stale error | timeout | invalid_header | updating | http_500
| http_502 | http_503 | http_504 | http_404 | off ...;
proxy_cache_methods¶
proxy_cache_methods GET | HEAD | POST ...;
问题¶
- proxy cache的流程是什么样的?
- proxy_cache, proxy_temp_path, proxy_store三种存储有什么差别?