dns的cache长期不能refresh,解决办法,重启
nginx多进程间的负载均衡
nginx是如何把任务分配到每个worker的呢?这种分配平均吗?合理吗?
通过strace 一个worker进程,部分逻辑如下:
我们发现,accept4是放在epoll_wait后面的,不难推测:
- nginx的epoll_wait 是在看那个文件描述符有事件发生了(就是需要处理了),当然,这里不包含listen的那个文件描述符(不是不能,是不应该);如果有事件发生,则处理,这些都是已经接收了的连接,有可能是(已建立的连接上的)新的请求。如果没有事件发生,则调用accept4看看有没有新的连接进来。这个逻辑就保证了,如果我比较闲,那么我就接活儿,如果我没闲着,我就不接活儿了
golang的chan阻塞与deadlock
示例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
func main() { c := make(chan int , 1) go func() { // 消费者 <-c }() go func() { // 如果没有这个协程,就得报deadlock而终止程序 i := 0 for { i++ } }() c <- 1 c <- 1 c <- 1 } |
如上程序:
如果没有第二个go协程,那么第一个协程是消费者,main协程是生产者,消费者死去后,就会出现deadlock错误; 原以为是runtime检测到我们在写一个没人消费的chan感到奇怪而报错,实际上不是的,甚至也不是写不进去而报错,而是,没有一个协程是能被执行的了(就好比陈佩斯的小偷中说的那样,这大半夜的也每个车让我指挥指挥),所以,runtime才感觉很迷茫,就报了个deadlock; 如果有第二个协程在的话,runtime会很高兴地去执行第二个协程的,真的不在意那个chan是否有人消费的。
kibana 搜索隐藏内容
1 |
$("span").each(function(k, v) { arr = $(v).html().match(/c_level=C.?/); if(arr && arr.length>0) console.log(arr[0]);}) |
hive transform
总是需要写一些transform放在hive上也挺麻烦,尤其这个transform还需要复杂的配置文件或者是访问IP首先等情况,还不见得能跑通,于是,我就发明了一个万能的transform:
1 |
hive -e "select transform(1) using 'nc 10.210.227.25 1234'" |
只需要在自己喜欢的机器上执行命令行程序就行,使用nc来做这个万能的transform,然而,自己的程序总是需要listen一个端口是不是也很麻烦,其实不难:
办法1:
使用 nc -l 10.210.227.25 1234 -e “your-command”
办法2: 如果你的nc版本太低,还不支持-e
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
package main import ( "flag" "net" "os" "os/exec" "strings" ) func main() { addr := flag.String("addr", ":1234", "[host]:port") cmdline := flag.String("cmd", "", "command") flag.Parse() command := strings.SplitN(*cmdline, ",,", -1) cmdName := command[0] args := command[1:] l, err := net.Listen("tcp", *addr) if err != nil { println(err.Error()) return } for { c, err := l.Accept() if err != nil { break } cmd := exec.Command(cmdName, args...) cmd.Stderr = os.Stderr cmd.Stdout = c cmd.Stdin = c go func() { if err := cmd.Run(); err != nil { println(err.Error()) } _ = c.Close() }() } } |
把这个编译一下,类似于nc的作用
注意:
使用transform时要注意:
1 |
hive -e "select transform(1) using 'nc 10.210.227.25 1234' from TableA limit 10" |
虽然这了有limit 10 ,你的transform干的可能不是10个的活儿,哪怕这个table只有一个file,可能和执行这个任务用到的机器数量有关;从这个角度来看,hive还不够聪明;
可能需要自己优化一下:
1 |
hive -e "select transform(1) using 'nc 10.210.227.25 1234' from (select * from TableA limit 10) a " |
transform 只能靠进程数量提高效率,没法在进程内并发?这个不担心乱序?
可以设置reducer的数量来限制并发。
transform的输出格式:
If there is no AS clause after USING my_script, Hive assumes that the output of the script contains 2 parts: key which is before the first tab, and value which is the rest after the first tab. Note that this is different from specifying AS key, value because in that case, value will only contain the portion between the first tab and the second tab if there are multiple tabs.
如果transform子句的using 后面没有as子句:
则输出被视为以第一个tab为分隔的两列,第一列是key,第二列是value;如果输出中没有tab,则整行都是第一列,第二列就是NULL;如果输出中有tab,则第一个tab之前的是第一列,第一个tab以后的都视为第二列
如果transform子句的using 后面有as子句:
则按照tab分隔视为多列
参考:
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Transform
usf3.0和2.1的区别体现在哪里_360doc个人图书馆
Probabilistic Data Structures for Go | Gopher Academy Blog
关于规则引擎
github上有不少关于规则引擎的项目,其中.net java 的比较多,go的就非常少。
https://github.com/topics/rules-engine
json的:
https://github.com/CacheControl/json-rules-engine
这个只是key op value 是否超过定义的规则
https://github.com/mithunsatheesh/node-rules
c#:
https://github.com/microsoft/RulesEngine
这个是编排工作流的
java:
https://github.com/selwynshen/nics-easy-rules
这里的思想可以看看
关于json规则引擎
1 2 3 4 5 6 7 8 9 10 11 12 |
{ "name": "transaction minimum", "priority": 3, "on" : true, "condition": function(R) { R.when(this.transactionTotal < 500); }, "consequence": function(R) { this.result = false; R.stop(); } } |
这个的特点是,可以直接在规则中定义函数; 这个适用于外包软件中的定制开发
golang 中的指针
模拟电路 之 三极管的基本使用
通常情况下,我们不必使用电压表和电流表; 直接使用探针就行了。