JS V8引擎

​https://www.zhihu.com/question/27428135/answer/2085274297?utm_source=wechat_session&utm_medium=social&utm_oi=631484691027464192&utm_content=group2_Answer&utm_campaign=shareopn​

JS V8优化,假如直接把JS代码解析成机器码,那么有两个问题1. 需要编译全量比较慢。2. 很多优化都做不了,比如耗的内存多(代码(5KB) --> 字节码(40KB) --> 机器码(10M))

解决方法是: 引入一层字节码

优化点主要有

1. 可以做函数的预解析,函数A调用函数B可以先不展开函数B,延迟执行

2. 假如函数B是很简单的函数,可以inline(内联)到函数A中

3. 基于字节码优化

----3.1 变量逃逸分析,假如一个变量不是逃逸的,我们可以把它放去寄存器中(而不需要放去内存)

----3.2 内联,可以合并冗余代码

收发文件

接收端: nc -l -p 5555 > file_name

发送端: cat /tmp/a > nc ${ip} 5555

关于如何设计appid/uid等,让业务解决更方便

常见工程技巧

 

debug python CPU 100%

1. strace & py-spy: https://groups.google.com/g/libuv/c/opFk74lww7k?pli=1

----1.1 apt-get install strace

----1.2 pip install py-spy

py-spy 0.3.11
Sampling profiler for Python programs

USAGE:
py-spy <SUBCOMMAND>

OPTIONS:
-h, --help Prints help information
-V, --version Prints version information

SUBCOMMANDS:
record Records stack trace information to a flamegraph, speedscope or raw file
top Displays a top like view of functions consuming CPU
dump Dumps stack traces for a target program to stdout
help Prints this

 

py-spy dump -ll --full-filenames -p 505


Process 505: python3 -m gevent.monkey --module xxx -k yyy -t 300 -w 1 -b :8888 main:app
Python v3.7.2 (/usr/local/bin/python3.7)

Thread 505 (active+gil)
__callback (/usr/local/lib/python3.7/site-packages/gevent/selectors.py:130)
Arguments:
self: <GeventSelector at 0x7f31e3ecc588>
events: 1
fd: 52
Locals:
cur_event_for_fd: 1
run (/usr/local/lib/python3.7/site-packages/gevent/hub.py:647)
Arguments:
self: <Hub at 0x7f31f3c50d08>
Locals:
loop: <gevent.libev.corecext.loop at 0x7f31f3c50ac8>
Thread 536 (idle)
wait (/usr/local/lib/python3.7/site-packages/gevent/_threading.py:68)
Arguments:
self: <_Condition at 0x7f314a9aac50>
wait_lock: <_thread.lock at 0x7f314a9c3468>
Locals:
gevent_threadpool_worker_idle: True
get (/usr/local/lib/python3.7/site-packages/gevent/_threading.py:158)
Arguments:
self: <Queue at 0x7f314a9b73a8>
cookie: <_thread.lock at 0x7f314a9c3468>
run (/usr/local/lib/python3.7/site-packages/gevent/threadpool.py:187)
Arguments:
self: <_WorkerGreenlet at 0x7f314a80c5c8>
Locals:
task: None
exc_info: <builtin_function_or_method at 0x7f31fb60a5a0>
fixup_hub_before_block: <method at 0x7f314aa2c4c8>
task_queue_get: <method at 0x7f314aa2c3c8>
task_queue_cookie: <_thread.lock at 0x7f314a9c3468>
run_task: <method at 0x7f31f025bf08>
task_queue_done: <method at 0x7f314aa95cc8>
Thread 537 (idle)
wait (/usr/local/lib/python3.7/site-packages/gevent/_threading.py:68)
Arguments:
self: <_Condition at 0x7f314a9aac50>
wait_lock: <_thread.lock at 0x7f314a9c35a8>
Locals:
gevent_threadpool_worker_idle: True
get (/usr/local/lib/python3.7/site-packages/gevent/_threading.py:158)
Arguments:
self: <Queue at 0x7f314a9b73a8>
cookie: <_thread.lock at 0x7f314a9c35a8>
run (/usr/local/lib/python3.7/site-packages/gevent/threadpool.py:187)
Arguments:
self: <_WorkerGreenlet at 0x7f314a80c678>
Locals:
task: None
exc_info: <builtin_function_or_method at 0x7f31fb60a5a0>
fixup_hub_before_block: <method at 0x7f314aa95648>
task_queue_get: <method at 0x7f314aa95548>
task_queue_cookie: <_thread.lock at 0x7f314a9c35a8>
run_task: <method at 0x7f314aa954c8>
task_queue_done: <method at 0x7f314aa95848>
Thread 538 (idle)
wait (/usr/local/lib/python3.7/site-packages/gevent/_threading.py:68)
Arguments:
self: <_Condition at 0x7f314a9aac50>
wait_lock: <_thread.lock at 0x7f314a9c3698>
Locals:
gevent_threadpool_worker_idle: True
get (/usr/local/lib/python3.7/site-packages/gevent/_threading.py:158)
Arguments:
self: <Queue at 0x7f314a9b73a8>
cookie: <_thread.lock at 0x7f314a9c3698>
run (/usr/local/lib/python3.7/site-packages/gevent/threadpool.py:187)
Arguments:
self: <_WorkerGreenlet at 0x7f314a80c728>
Locals:
task: None
exc_info: <builtin_function_or_method at 0x7f31fb60a5a0>
fixup_hub_before_block: <method at 0x7f314aa95d08>
task_queue_get: <method at 0x7f314aa95888>
task_queue_cookie: <_thread.lock at 0x7f314a9c3698>
run_task: <method at 0x7f314aa95f88>
task_queue_done: <method at 0x7f314aa950c8>
Thread 541 (idle)
wait (/usr/local/lib/python3.7/site-packages/gevent/_threading.py:68)
Arguments:
self: <_Condition at 0x7f314a9aac50>
wait_lock: <_thread.lock at 0x7f314a9c3788>
Locals:
gevent_threadpool_worker_idle: True
get (/usr/local/lib/python3.7/site-packages/gevent/_threading.py:158)
Arguments:
self: <Queue at 0x7f314a9b73a8>
cookie: <_thread.lock at 0x7f314a9c3788>
run (/usr/local/lib/python3.7/site-packages/gevent/threadpool.py:187)
Arguments:
self: <_WorkerGreenlet at 0x7f314a80c7d8>
Locals:
task: None
exc_info: <builtin_function_or_method at 0x7f31fb60a5a0>
fixup_hub_before_block: <method at 0x7f314aa94948>
task_queue_get: <method at 0x7f314aa94088>
task_queue_cookie: <_thread.lock at 0x7f314a9c3788>
run_task: <method at 0x7f314aa88208>
task_queue_done: <method at 0x7f314aa94a08>
Thread 542 (idle)
wait (/usr/local/lib/python3.7/site-packages/gevent/_threading.py:68)
Arguments:
self: <_Condition at 0x7f314a9aac50>
wait_lock: <_thread.lock at 0x7f314a9c3878>
Locals:
gevent_threadpool_worker_idle: True
get (/usr/local/lib/python3.7/site-packages/gevent/_threading.py:158)
Arguments:
self: <Queue at 0x7f314a9b73a8>
cookie: <_thread.lock at 0x7f314a9c3878>
run (/usr/local/lib/python3.7/site-packages/gevent/threadpool.py:187)
Arguments:
self: <_WorkerGreenlet at 0x7f314a80c888>
Locals:
task: None
exc_info: <builtin_function_or_method at 0x7f31fb60a5a0>
fixup_hub_before_block: <method at 0x7f314aa95308>
task_queue_get: <method at 0x7f314aa95208>
task_queue_cookie: <_thread.lock at 0x7f314a9c3878>
run_task: <method at 0x7f314aa95188>
task_queue_done: <method at 0x7f314aa95408>
Thread 543 (idle)
wait (/usr/local/lib/python3.7/site-packages/gevent/_threading.py:68)
Arguments:
self: <_Condition at 0x7f314a9aac50>
wait_lock: <_thread.lock at 0x7f314a9c3968>
Locals:
gevent_threadpool_worker_idle: True
get (/usr/local/lib/python3.7/site-packages/gevent/_threading.py:158)
Arguments:
self: <Queue at 0x7f314a9b73a8>
cookie: <_thread.lock at 0x7f314a9c3968>
run (/usr/local/lib/python3.7/site-packages/gevent/threadpool.py:187)
Arguments:
self: <_WorkerGreenlet at 0x7f314a80c938>
Locals:
task: None
exc_info: <builtin_function_or_method at 0x7f31fb60a5a0>
fixup_hub_before_block: <method at 0x7f314aa94bc8>
task_queue_get: <method at 0x7f314aa94d88>
task_queue_cookie: <_thread.lock at 0x7f314a9c3968>
run_task: <method at 0x7f314aa94c08>
task_queue_done: <method at 0x7f314aa94e08>
Thread 544 (idle)
wait (/usr/local/lib/python3.7/site-packages/gevent/_threading.py:68)
Arguments:
self: <_Condition at 0x7f314a9aac50>
wait_lock: <_thread.lock at 0x7f314a9c3a58>
Locals:
gevent_threadpool_worker_idle: True
get (/usr/local/lib/python3.7/site-packages/gevent/_threading.py:158)
Arguments:
self: <Queue at 0x7f314a9b73a8>
cookie: <_thread.lock at 0x7f314a9c3a58>
run (/usr/local/lib/python3.7/site-packages/gevent/threadpool.py:187)
Arguments:
self: <_WorkerGreenlet at 0x7f314a80c9e8>
Locals:
task: None
exc_info: <builtin_function_or_method at 0x7f31fb60a5a0>
fixup_hub_before_block: <method at 0x7f314aa95c48>
task_queue_get: <method at 0x7f314aa95c08>
task_queue_cookie: <_thread.lock at 0x7f314a9c3a58>
run_task: <method at 0x7f314aa95b88>
task_queue_done: <method at 0x7f314aa95b48>
Thread 545 (idle)
wait (/usr/local/lib/python3.7/site-packages/gevent/_threading.py:68)
Arguments:
self: <_Condition at 0x7f314a9aac50>
wait_lock: <_thread.lock at 0x7f314a9c3b48>
Locals:
gevent_threadpool_worker_idle: True
get (/usr/local/lib/python3.7/site-packages/gevent/_threading.py:158)
Arguments:
self: <Queue at 0x7f314a9b73a8>
cookie: <_thread.lock at 0x7f314a9c3b48>
run (/usr/local/lib/python3.7/site-packages/gevent/threadpool.py:187)
Arguments:
self: <_WorkerGreenlet at 0x7f314a80ca98>
Locals:
task: None
exc_info: <builtin_function_or_method at 0x7f31fb60a5a0>
fixup_hub_before_block: <method at 0x7f314aa94e88>
task_queue_get: <method at 0x7f314aa94cc8>
task_queue_cookie: <_thread.lock at 0x7f314a9c3b48>
run_task: <method at 0x7f314aa94f08>
task_queue_done: <method at 0x7f314aa95448>
Thread 8013 (idle)
wait (/usr/local/lib/python3.7/site-packages/gevent/_threading.py:68)
Arguments:
self: <_Condition at 0x7f314a9aac50>
wait_lock: <_thread.lock at 0x7f314a8410a8>
Locals:
gevent_threadpool_worker_idle: True
get (/usr/local/lib/python3.7/site-packages/gevent/_threading.py:158)
Arguments:
self: <Queue at 0x7f314a9b73a8>
cookie: <_thread.lock at 0x7f314a8410a8>
run (/usr/local/lib/python3.7/site-packages/gevent/threadpool.py:187)
Arguments:
self: <_WorkerGreenlet at 0x7f31e421ef68>
Locals:
task: None
exc_info: <builtin_function_or_method at 0x7f31fb60a5a0>
fixup_hub_before_block: <method at 0x7f31e1d45448>
task_queue_get: <method at 0x7f314aafe188>
task_queue_cookie: <_thread.lock at 0x7f314a8410a8>
run_task: <method at 0x7f314ab03988>
task_queue_done: <method at 0x7f314aafe208>
Thread 8075 (idle)
wait (/usr/local/lib/python3.7/site-packages/gevent/_threading.py:68)
Arguments:
self: <_Condition at 0x7f314a9aac50>
wait_lock: <_thread.lock at 0x7f31ef62be40>
Locals:
gevent_threadpool_worker_idle: True
get (/usr/local/lib/python3.7/site-packages/gevent/_threading.py:158)
Arguments:
self: <Queue at 0x7f314a9b73a8>
cookie: <_thread.lock at 0x7f31ef62be40>
run (/usr/local/lib/python3.7/site-packages/gevent/threadpool.py:187)
Arguments:
self: <_WorkerGreenlet at 0x7f31ef523eb8>
Locals:
task: None
exc_info: <builtin_function_or_method at 0x7f31fb60a5a0>
fixup_hub_before_block: <method at 0x7f31ef5d0d08>
task_queue_get: <method at 0x7f31ef5c2508>
task_queue_cookie: <_thread.lock at 0x7f31ef62be40>
run_task: <method at 0x7f31ef5c2e48>
task_queue_done: <method at 0x7f314aa38588>

 

 

​设置自启动sock5代理​​​运行 ssh -qTfnN -D 7070 xx.xx.xx.xx
运行 ps -elf | grep ssh 确认有 ssh进程在监听7070端口.
启动 Startup Applications程序
将ssh -qTfnN -D 7070 xx.xx.xx.xx 新建成一个自动启动项.

 

通过命令行打开chrome:google-chrome --proxy-server=socks5://127.0.0.1:7070
此时的Chrome是可以FQ的,登陆后在插件Store搜索SwitchyOmega并安装。
配置插件,将Proxy设为socks5、127.0.0.1、7070端口。右上角图标设为AutoSwitch后可配置白名单列表来决定哪些域名走代理哪些直连。

 

ssh:

ServerAliveInterval 60  60s后,client发给server一段话

 

-q 静默模式

-T 禁止分配伪终端

-f 后台运行

-n 把 stdin 重定向到 /dev/null (实际上防止从 stdin 读取数据). 在后台运行时一定会用到这个选项. 它的常用技巧是远程运行 X11 程序. 例如, ssh -n shadows.cs.hut.fi emacs 将会在 shadows.cs.hut.fi 上启动 emacs, 同时自动在加密通道中转发 X11 连接. 在后台运行. (但是如果 要求口令或密语, 这种方式就无法工作; 参见 -f 选项.)

-N 不执行远程命令. 用于转发端口. (仅限协议第二版)

-p 指定端口

 

 

python中:

come

  yy

    __init__.py

    aa.py

  main.py

可以在main.py中,这样来导入aa(其中aa有fun和hello两个函数)

1、from yy.aa import fun   (注意不能使用from come.yy.aa import fun,无论come文件夹是否有__init__.py)

2、import yy.aa  (然后yy.aa.fun())

3、import yy.aa as vimi (然后vimi.test)

 

-----------------

 

 

缓存的东西,缓存已经存在的最新的,就比较优秀