snoopyxdy的博客

不要用执行上的勤奋来掩盖思考上的懒惰


  • 首页

  • 归档

记录一个openresty路由算法的优化

发表于 2018-01-31 | 更新于 2018-11-26 | 分类于 openresty

最近在做一个Apigateway项目,目标就是做成类似AWS的Apigateway那样,但是只需要支持HTTP协议即可,由于配置非常灵活,而且性能要求比较高,我还是选择了 openresty 来作为这个网关的技术栈。但是我们需要对nginx.conf文件做一个改造,要做到添加或删除 路径的配置,修改Upstream的内容等都不能reload重启nginx,所以nginx原生的路由匹配功能我们就无法利用了。只能通过lua代码自己去匹配。

阅读全文 »

记录一个ngx.say和ngx.print差异导致的线上bug

发表于 2018-01-16 | 更新于 2018-11-26 | 分类于 lua

最近上线一个项目,利用openresty在前面做反向代理,部分地址通过lua的http请求后端接口进行返回,在线下测试都没问题,公司预发灰度测试都通过了,但是上线到微信站,就莫名其妙的报错了。

阅读全文 »

由ngx.say和ngx.print差异引发的血案

发表于 2018-01-16 | 更新于 2018-11-26 | 分类于 openresty

最近上线一个项目,利用openresty在前面做反向代理,部分地址通过lua的http请求后端接口进行返回,在线下测试都没问题,公司预发灰度测试都通过了,但是上线到微信站,就莫名其妙的报错了。

阅读全文 »

利用CA证书签名任意域名的SSL证书

发表于 2018-01-16 | 更新于 2018-11-26 | 分类于 openresty

最近想做一个简单的HTTPS抓包小工具,记录一下生成一个域名的证书并用CA证书对他进行签名的简单过程。

阅读全文 »

记录一个因为nginx配置不规范导致的缓存击穿的问题

发表于 2017-10-20 | 更新于 2018-11-26 | 分类于 lua

之前我们公司有一个页面是处于内存缓存系统的保护的,缓存的规则就是根据请求的 uri 部分进行缓存,但是不关心参数部分。

突然有一天,缓存命中率下降的很厉害,而且后端页面的负载也飙高了。

阅读全文 »

nginx配置不规范导致的缓存击穿

发表于 2017-10-20 | 更新于 2018-11-26 | 分类于 nginx

之前我们公司有一个页面是处于内存缓存系统的保护的,缓存的规则就是根据请求的 uri 部分进行缓存,但是不关心参数部分。

突然有一天,缓存命中率下降的很厉害,而且后端页面的负载也飙高了。

阅读全文 »

or保持50并发请求第三方接口

发表于 2017-09-25 | 更新于 2018-11-26 | 分类于 openresty

当时有一个需求,发送1w个请求,保持50个并发,用or实现代码如下:

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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
_M.parallel = function(self)
local coNum = 50
local reqList = {}
for i=1,10000,1 do
table.insert(reqList, 'http://127.0.0.1:6565/respParallel')
end

local count = 0

local reqFunc = function(i)

-- ngx.log(ngx.ERR, "============", count, #reqList, "=======")

while count <= #reqList do
ngx.sleep(0)
count = count + 1
local request_url = reqList[count]
if not request_url then
break
end

-- 发送http请求获取od和map的对应关系
local httpc = http.new()
httpc:set_timeout(60000)
-- 拼接请求参数
local opt = {
method = "GET",
}

local res, err = httpc:request_uri(request_url, opt)
if err then
--ngx.log(ngx.ERR, string.format("thread [%s] request error count [%s] error, %s", i, count, err))
else
--ngx.log(ngx.ERR, string.format("thread [%s] request complete count[%s], body [%s]", i, count, res.body))
end
end

local msg = "thread [%s] complete"
--ngx.log(ngx.ERR, string.format(msg, i))

return msg
end


local threads = {}
for i=0,coNum,1 do
table.insert(threads, (ngx.thread.spawn(reqFunc, i)))
end


for i = 1, #threads do
local result = ngx.thread.wait(threads[i])
ngx.say(result)
end

local result, err = ngx.shared.cachDict:get("pcount")
ngx.say(string.format("=== total: %s ===", result))

return ""

end

git回滚master到指定commit

发表于 2017-07-12 | 更新于 2018-11-26 | 分类于 git

新建old_master分支做备份

1
git branch old_master

push到远程

1
git push origin old_master:old_master

本地仓库回退到某个版本

1
git reset –hard bae168

删除远程的master分支

1
git push origin :master

重新创建master分支

1
git push origin master

golang遍历结构体

发表于 2017-06-23 | 更新于 2018-11-26 | 分类于 golang

很多时候,我们可能会需要结构体赋值,又不想一个个字段的写,可以利用结构体遍历赋值

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
package main
import (
"fmt"
"reflect"
)
type NotknownType struct {
s1, s2, s3 string
}
var secret interface{} = NotknownType{"Ada", "Go", "Oberon"}
func main() {
value := reflect.ValueOf(secret)
for i := 0; i < value.NumField(); i++ {
fmt.Printf("Field %d: %v, %s; \n", i, value.Field(i), value.FieldByName("s1"))
}
}

go里面的几种继承写法

发表于 2017-06-22 | 更新于 2018-11-26 | 分类于 golang

go里面的几种继承写法

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
42
43
package main

import (
"fmt"
)

type s1 struct {
a string
}
type s2 struct {
s s1
x string
}
type s3 struct {
s1
x string
}
type s4 struct {
*s1
x string
}
func main() {

x2 := s2{}
x2.s.a = "1"
x2.x = "2"

x3 := s3{}
x3.a = "1"
x3.s1.a = "2"
x3.x = "3"
fmt.Println(x3.a, x3.s1.a)

x4 := s4{
&s1{},
"3",
}
x4.a = "1"
x4.s1.a = "2"
x4.x = "3"
fmt.Println(x4.a, x4.s1.a)

}

用哪种看自己喜欢了

输出:

1
2
2,2
2,2

123…29

snoopyxdy

289 日志
13 分类
23 标签
© 2020 snoopyxdy
由 Hexo 强力驱动 v3.8.0
|
主题 – NexT.Muse v6.5.0