Skip to content

学习笔记

开发工具栈

1. sublime
2. zsh + oh-my-zsh
3. tmux
4. vim
5. 常用配置: <https://github.com/seamile/Weeds/tree/master/rc.d>

限制访问频率

频率最大为每秒 2 次

    requests     time.time()
    --------     -----------
    request 1 -> 1000.000
    request 2 -> 1000.230
    request 3 -> 1001.930
    request 4 -> 1002.900
    request 5 -> (1003.130 - 1001.930) < 1
    request 6 -> 1003.140
    request 7 -> 1003.140
    request 8 -> 1003.140
    request 9 -> 1003.140
    request 10 -> 1003.140
    request 11 -> 1003.140

Tags

  1. 多对多关系,一般建立一个关系表

Article 表 id

Tag 表 id name

关系表 article_id tag_id

创建或更新过程

文章 Article(33)

   1        2         3

原来的 'python', 'django', 'linux' 传入 'python', 'django', 'mongodb' 4

ArticleTags

33 1 33 2

33 4

权限管理功能

做设计时要有 “前瞻性”

给用户添加权限

user id

permission id

group id pid

参考链接 https://www.zhihu.com/question/20313385http://blog.csdn.net/painsonline/article/details/7183613/

Gunicorn

多进程 + 协程 (greenlet)

Gunicorn uWSGI

压力测试 ab (Apache Bench) webbench autobench

RPS 每秒请求量 QPS 每秒查询量

10 Concurrency 1000 Request gunicorn 614 r/s django 510 r/s

Unix 一切皆文件

文件描述符

Nginx

正向代理

内网环境 -> 代理 -> 公网机器

反向代理

用户 -> Nginx -> 服务器内网环境

DB 集群

读写分离

主从结构

 写     读
 |      ^
 V      |
主机 -> 从机

一主两从甚至一主多从

双主互备

主机 <-> 主机

     从

CDN

北京 源站 上海 镜像站 深圳 镜像站 乌鲁木齐 镜像站 . . . 美国 镜像站