-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Profile base to dev #352
Profile base to dev #352
Conversation
* Profile base add metric (#338) * Optimise filter addMetric * Profile base findcluster (#340) * Profile base findcluster (#337) * Profile base do acccesslog (#339) * bugfix: BytesBuffer.Reset (#334) * Access log (#336) * Profile base do accesslog (#343) Accesslogv2 (#342) * Profile base preview escape (#345) * optimise Escape * Profile base timenow (#344) (#347) * Profile base do accesslog (#343) * update: log/bytesbuffer (#341) * bytesBuffer release * Accesslogv2 (#346) * update: log/bytesbuffer
* code beautify
* code beautify
* code beautify
motan2 endpoint
# Conflicts: # protocol/motanProtocol.go
* code beautify
* memory copy & bytesBuffer resue
* code beautify
* code beautify
* code beautify
agent.go
Outdated
@@ -437,7 +442,7 @@ func (a *Agent) initHTTPClusters() { | |||
} | |||
httpCluster := cluster.NewHTTPCluster(url, true, a.Context, a.extFactory) | |||
if httpCluster == nil { | |||
vlog.Errorf("Create http cluster %s failed", id) | |||
vlog.Errorf("—Create http cluster %s failed", id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
agent.go
Outdated
@@ -490,7 +490,7 @@ func (a *Agent) reloadClusters(ctx *motan.Context) { | |||
} | |||
|
|||
service := url.Path | |||
mapKey := getClusterKey(url.Group, url.GetStringParamsWithDefault(motan.VersionKey, "0.1"), url.Protocol, url.Path) | |||
mapKey := getClusterKey(url.Group, url.GetStringParamsWithDefault(motan.VersionKey, "1.0"), url.Protocol, url.Path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
默认版本号改为全局常量(包含其他相关处)
if motanReq, ok := mreq.(*motan.MotanRequest); ok { | ||
motan.ReleaseMotanRequest(motanReq) | ||
} | ||
if motanResp, ok := mres.(*motan.MotanResponse); ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
对mres的HttpMotanResponse类型判断放在else中,不需要重复判断两次
agent_test.go
Outdated
{"test", "g1", "http", "1.3", "No refers for request"}, | ||
{"test", "g1", "http", "1.2", "less condition to select cluster"}, | ||
{"test", "b", "c", "d", "no cluster matches the request"}, | ||
// 同一个service有多个cluster可以匹配,但是group没有传 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
改成英文注释吧
core/bytes.go
Outdated
if bb.buf == nil { | ||
bb.buf = make([]byte, initSize) | ||
} | ||
if bb.temp == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
默认属性(temp)的初始化都放到池构造func中,不用对每个buf都做判空了。buf是因为涉及到初始大小的问题,与此方法的入参相关,可以放在这里
@@ -433,23 +448,27 @@ func MotanRequestToFasthttpRequest(motanRequest core.Request, fasthttpRequest *f | |||
motanRequest.GetAttachments().Range(func(k, v string) bool { | |||
// ignore some specified key | |||
for _, attachmentKey := range httpProxySpecifiedAttachments { | |||
if strings.EqualFold(k, attachmentKey) { | |||
if k == attachmentKey { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
优化匹配逻辑,命中概率大的放在前面快速终止流程。比如InnerAttachmentsConvertMap的匹配
http/httpProxy.go
Outdated
@@ -501,12 +520,13 @@ func FasthttpResponseToMotanResponse(motanResponse core.Response, fasthttpRespon | |||
fasthttpResponse.Header.VisitAll(func(k, v []byte) { | |||
motanResponse.SetAttachment(string(k), string(v)) | |||
}) | |||
if resp, ok := motanResponse.(*core.MotanResponse); ok { | |||
if resp, ok := motanResponse.(*core.HttpMotanResponse); ok { | |||
httpResponseBody := fasthttpResponse.Body() | |||
if httpResponseBody != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
没有必要判空
log/bytes.go
Outdated
|
||
func acquireBytesBuffer() *innerBytesBuffer { | ||
b := innerBytesBufferPool.Get() | ||
if b == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不会为nil
log/log.go
Outdated
@@ -390,12 +391,13 @@ func (d *defaultLogger) doAccessLog(logObject *AccessLogEntity) { | |||
zap.String("exception", logObject.Exception), | |||
zap.String("upstreamCode", logObject.UpstreamCode)) | |||
} else { | |||
var buffer bytes.Buffer | |||
buffer := newInnerBytesBuffer() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
改用acquireBytesBuffer,显示使用池化buffer
log/log.go
Outdated
|
||
func AcquireAccessLogEntity() *AccessLogEntity { | ||
v := accessLogEntityPool.Get() | ||
if v == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
无效分支
endpoint/motanCommonEndpoint.go
Outdated
s.channel.heartbeatLock.Unlock() | ||
} else { | ||
s.channel.streamLock.Lock() | ||
delete(s.channel.streams, s.streamId) | ||
if _, exist = s.channel.heartbeats[s.streamId]; exist { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove的不对
endpoint/motanCommonEndpoint.go
Outdated
default: | ||
} | ||
//use atomic.Swap avoid data race between goroutines(Channel.Call and Stream.notify) when ReleaseStream | ||
atomic.SwapPointer((*unsafe.Pointer)(unsafe.Pointer(&s.channel)), nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
channel重置了多次;
res需要重置,避免长时间持有大对象;
endpoint/motanCommonEndpoint.go
Outdated
select { | ||
case <-s.recvNotifyCh: | ||
msg := s.res | ||
if msg == nil { | ||
return nil, errors.New("recv err: recvMsg is nil") | ||
} | ||
return msg, nil | ||
case <-timer.C: | ||
case <-s.timer.C: | ||
s.release = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
需要在注释解释stream的release机制,几个关键点:stream重置后初值默认进行回收;Channel.Call是唯一回收点;当超时等特殊情况,回收状态需要由remove重新决定
protocol/motanProtocol.go
Outdated
// DecodeWithTime the parameter rs is a slice pointer, so the | ||
// extension of *rs will affect the slice outside in order to | ||
// reuse the readSlice which is used by reading header info from buf | ||
func DecodeWithTime(buf *bufio.Reader, rs *[]byte, maxContentLength int) (msg *Message, start time.Time, err error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rs参数命名调整。tempBuf之类的
protocol/motanProtocol.go
Outdated
metabuf := motan.NewBytesBuffer(256) | ||
// EncodeWithoutBody encode message expect Message.Body | ||
// unexpected if call Message.GetEncodedBytes after rewrite result(*motan.BytesBuffer) | ||
func (msg *Message) EncodeWithoutBody() *motan.BytesBuffer { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不用和Encode方法进行区分,不用显示表明body处理方式,由Encode方法不再返回结果,只能使用GetEncodedBytes方法强制限定使用姿势
protocol/motanProtocol.go
Outdated
msg.Metadata.Range(func(k, v string) bool { | ||
if k == "" || v == "" { | ||
return true | ||
if VerifyMeta(k, v) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为啥拆分开?
protocol/motanProtocol.go
Outdated
func DecodeWithTime(buf *bufio.Reader, maxContentLength int) (msg *Message, start time.Time, err error) { | ||
temp := make([]byte, HeaderLength, HeaderLength) | ||
|
||
func DecodeWithoutBody(buf *bufio.Reader, rs *[]byte, maxContentLength int) (msg *Message, bodySize int, err error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不需要单独拆分方法,这个方法没有复用的场景,也不会进行内联
protocol/motanProtocol.go
Outdated
@@ -660,11 +740,15 @@ func ConvertToResMessage(response motan.Response, serialize motan.Serialization) | |||
res.Body = b | |||
} else { | |||
vlog.Warningf("convert response value fail! serialized value not []byte. res:%+v", response) | |||
res.SetAlreadySend() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alreadySend改为canRelease
provider/httpProvider.go
Outdated
@@ -140,6 +140,20 @@ func (h *HTTPProvider) SetContext(context *motan.Context) { | |||
h.gctx = context | |||
} | |||
|
|||
// Rewrite do rewrite | |||
func (h *HTTPProvider) Rewrite(httpReq *fasthttp.Request, request motan.Request) (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
改为私有方法
return resp | ||
} | ||
resp.RequestID = request.GetRequestID() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
给response赋值requestid的语句呢?
provider/httpProvider.go
Outdated
//do rewrite | ||
rewritePath := request.GetMethod() | ||
var err error | ||
if h.enableRewrite { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
f h.enableRewrite 的判定可以放到Rewrite方法中
provider/httpProvider.go
Outdated
err := mhttp.MotanRequestToFasthttpRequest(request, httpReq, h.defaultHTTPMethod) | ||
if err != nil { | ||
fillExceptionWithCode(resp, http.StatusBadRequest, t, err) | ||
if h.enableHttpException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
判定条件合并。下同
* memory copy & bytesBuffer resue
* use ants pool
Profile base code beautify
No description provided.