MM-25516: Changed to byte slice instead of string for cluster messages (#17998)
* MM-25516: Changed to byte slice instead of string for cluster messages https://mattermost.atlassian.net/browse/MM-25116 Testing: Manually tested. Load-tested with Cluster Controller. I looked into changing the serialization method to use msgpack, but the ClusterMessage struct was mainly used for only 3 fields which didn't lead to much of a CPU time improvement, whereas actually led to more allocations using msgpack. Hence, I chose to remain with JSON. ``` name old time/op new time/op delta ClusterMarshal-8 3.51µs ± 1% 3.10µs ± 2% -11.59% (p=0.000 n=9+10) name old alloc/op new alloc/op delta ClusterMarshal-8 776B ± 0% 1000B ± 0% +28.87% (p=0.000 n=10+10) name old allocs/op new allocs/op delta ClusterMarshal-8 12.0 ± 0% 13.0 ± 0% +8.33% (p=0.000 n=10+10) ``` ```release-note Changed the field type of Data in model.ClusterMessage to []byte from string. ``` * Trigger CI ```release-note NONE ```
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
23800326a0
Коммит
7be61af24f
@@ -77,7 +77,7 @@ const (
|
||||
)
|
||||
|
||||
type WebSocketMessage interface {
|
||||
ToJson() string
|
||||
ToJson() []byte
|
||||
IsValid() bool
|
||||
EventType() string
|
||||
}
|
||||
@@ -199,9 +199,9 @@ func (ev *WebSocketEvent) EventType() string {
|
||||
return ev.event
|
||||
}
|
||||
|
||||
func (ev *WebSocketEvent) ToJson() string {
|
||||
func (ev *WebSocketEvent) ToJson() []byte {
|
||||
if ev.precomputedJSON != nil {
|
||||
return fmt.Sprintf(`{"event": %s, "data": %s, "broadcast": %s, "seq": %d}`, ev.precomputedJSON.Event, ev.precomputedJSON.Data, ev.precomputedJSON.Broadcast, ev.GetSequence())
|
||||
return []byte(fmt.Sprintf(`{"event": %s, "data": %s, "broadcast": %s, "seq": %d}`, ev.precomputedJSON.Event, ev.precomputedJSON.Data, ev.precomputedJSON.Broadcast, ev.GetSequence()))
|
||||
}
|
||||
b, _ := json.Marshal(webSocketEventJSON{
|
||||
ev.event,
|
||||
@@ -209,7 +209,7 @@ func (ev *WebSocketEvent) ToJson() string {
|
||||
ev.broadcast,
|
||||
ev.sequence,
|
||||
})
|
||||
return string(b)
|
||||
return b
|
||||
}
|
||||
|
||||
// Encode encodes the event to the given encoder.
|
||||
@@ -280,9 +280,9 @@ func (m *WebSocketResponse) EventType() string {
|
||||
return WebsocketEventResponse
|
||||
}
|
||||
|
||||
func (m *WebSocketResponse) ToJson() string {
|
||||
func (m *WebSocketResponse) ToJson() []byte {
|
||||
b, _ := json.Marshal(m)
|
||||
return string(b)
|
||||
return b
|
||||
}
|
||||
|
||||
func WebSocketResponseFromJson(data io.Reader) *WebSocketResponse {
|
||||
|
||||
Ссылка в новой задаче
Block a user