Skip to content

Commit

Permalink
add write-xid (micro-optimizations)
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Aizman <[email protected]>
  • Loading branch information
alex-aizman committed Sep 8, 2024
1 parent 7b0b0bc commit 68858f9
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 31 deletions.
8 changes: 8 additions & 0 deletions ais/htcommon.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"net/url"
"os"
rdebug "runtime/debug"
"strconv"
"strings"
"sync"
"syscall"
Expand Down Expand Up @@ -831,6 +832,13 @@ func apiReqFree(a *apiRequest) {
// misc helpers
//

// http response: xaction ID most of the time but may be any string
func writeXid(w http.ResponseWriter, xid string) {
debug.Assert(xid != "")
w.Header().Set(cos.HdrContentLength, strconv.Itoa(len(xid)))
w.Write(cos.UnsafeB(xid))
}

func newBckFromQ(bckName string, query url.Values, dpq *dpq) (*meta.Bck, error) {
bck := _bckFromQ(bckName, query, dpq)
normp, err := cmn.NormalizeProvider(bck.Provider)
Expand Down
17 changes: 9 additions & 8 deletions ais/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -954,8 +954,7 @@ func (p *proxy) httpbckdelete(w http.ResponseWriter, r *http.Request, apireq *ap
p.writeErr(w, r, err)
return
}
w.Header().Set(cos.HdrContentLength, strconv.Itoa(len(xid)))
w.Write([]byte(xid))
writeXid(w, xid)
default:
p.writeErrAct(w, r, msg.Action)
}
Expand Down Expand Up @@ -1182,8 +1181,7 @@ func (p *proxy) httpbckput(w http.ResponseWriter, r *http.Request) {
}
xid, err := p.createArchMultiObj(bckFrom, bckTo, msg)
if err == nil {
w.Header().Set(cos.HdrContentLength, strconv.Itoa(len(xid)))
w.Write([]byte(xid))
writeXid(w, xid)
} else {
p.writeErr(w, r, err)
}
Expand Down Expand Up @@ -1449,8 +1447,7 @@ func (p *proxy) _bckpost(w http.ResponseWriter, r *http.Request, msg *apc.ActMsg
}

debug.Assertf(xact.IsValidUUID(xid) || strings.IndexByte(xid, ',') > 0, "%q: %q", msg.Action, xid)
w.Header().Set(cos.HdrContentLength, strconv.Itoa(len(xid)))
w.Write([]byte(xid))
writeXid(w, xid)
}

// init existing or create remote
Expand Down Expand Up @@ -1840,7 +1837,9 @@ func (p *proxy) httpobjpost(w http.ResponseWriter, r *http.Request, apireq *apiR
p.writeErr(w, r, err)
return
}
w.Write([]byte(xid))
if xid != "" {
writeXid(w, xid)
}
case apc.ActBlobDl:
if err := p.checkAccess(w, r, bck, apc.AccessRW); err != nil {
return
Expand Down Expand Up @@ -2051,7 +2050,9 @@ func (p *proxy) httpbckpatch(w http.ResponseWriter, r *http.Request, apireq *api
p.writeErr(w, r, err)
return
}
w.Write([]byte(xid))
if xid != "" {
writeXid(w, xid)
}
}

// HEAD /v1/objects/bucket-name/object-name
Expand Down
4 changes: 1 addition & 3 deletions ais/prxbsumm.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package ais
import (
"net/http"
"net/url"
"strconv"

"github.com/NVIDIA/aistore/api/apc"
"github.com/NVIDIA/aistore/cmn"
Expand All @@ -32,8 +31,7 @@ func (p *proxy) bsummact(w http.ResponseWriter, r *http.Request, qbck *cmn.Query
p.writeErr(w, r, err)
} else {
w.WriteHeader(http.StatusAccepted)
w.Header().Set(cos.HdrContentLength, strconv.Itoa(len(msg.UUID)))
w.Write([]byte(msg.UUID))
writeXid(w, msg.UUID)
}
return
}
Expand Down
14 changes: 4 additions & 10 deletions ais/prxclu.go
Original file line number Diff line number Diff line change
Expand Up @@ -1264,9 +1264,7 @@ func (p *proxy) xstart(w http.ResponseWriter, r *http.Request, msg *apc.ActMsg)
smap := p.owner.smap.get()
nl := xact.NewXactNL(xargs.ID, xargs.Kind, &smap.Smap, nil)
p.ic.registerEqual(regIC{smap: smap, nl: nl})

w.Header().Set(cos.HdrContentLength, strconv.Itoa(len(xargs.ID)))
w.Write([]byte(xargs.ID))
writeXid(w, xargs.ID)
}
}

Expand Down Expand Up @@ -1362,9 +1360,7 @@ func (p *proxy) rebalanceCluster(w http.ResponseWriter, r *http.Request, msg *ap
p.writeErr(w, r, err)
return
}
debug.Assert(rmdCtx.rebID != "")
w.Header().Set(cos.HdrContentLength, strconv.Itoa(len(rmdCtx.rebID)))
w.Write([]byte(rmdCtx.rebID))
writeXid(w, rmdCtx.rebID)
}

func (p *proxy) sendOwnTbl(w http.ResponseWriter, r *http.Request, msg *apc.ActMsg) {
Expand Down Expand Up @@ -1509,8 +1505,7 @@ func (p *proxy) rmNode(w http.ResponseWriter, r *http.Request, msg *apc.ActMsg)
return
}
if rebID != "" {
w.Header().Set(cos.HdrContentLength, strconv.Itoa(len(rebID)))
w.Write(cos.UnsafeB(rebID))
writeXid(w, rebID)
}
}
}
Expand Down Expand Up @@ -1651,8 +1646,7 @@ func (p *proxy) stopMaintenance(w http.ResponseWriter, r *http.Request, msg *apc
return
}
if rebID != "" {
w.Header().Set(cos.HdrContentLength, strconv.Itoa(len(rebID)))
w.Write(cos.UnsafeB(rebID))
writeXid(w, rebID)
}
}

Expand Down
4 changes: 2 additions & 2 deletions ais/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -998,8 +998,8 @@ func (t *target) httpobjpost(w http.ResponseWriter, r *http.Request, apireq *api
}
if xid, _, err = t.blobdl(args, nil /*oa*/); xid != "" {
debug.AssertNoErr(err)
w.Header().Set(cos.HdrContentLength, strconv.Itoa(len(xid)))
w.Write([]byte(xid))
writeXid(w, xid)

// lom is eventually freed by x-blob
}
default:
Expand Down
4 changes: 1 addition & 3 deletions ais/tgtetl.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"fmt"
"net/http"
"net/url"
"strconv"

"github.com/NVIDIA/aistore/api/apc"
"github.com/NVIDIA/aistore/cmn"
Expand Down Expand Up @@ -196,8 +195,7 @@ func (t *target) healthETL(w http.ResponseWriter, r *http.Request, etlName strin
}
return
}
w.Header().Set(cos.HdrContentLength, strconv.Itoa(len(health)))
w.Write([]byte(health))
writeXid(w, health)
}

func (t *target) metricsETL(w http.ResponseWriter, r *http.Request, etlName string) {
Expand Down
6 changes: 2 additions & 4 deletions ais/tgtxact.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package ais
import (
"fmt"
"net/http"
"strconv"
"sync"

"github.com/NVIDIA/aistore/api/apc"
Expand Down Expand Up @@ -132,9 +131,8 @@ func (t *target) httpxput(w http.ResponseWriter, r *http.Request) {
t.writeErr(w, r, err)
return
}
if l := len(xid); l > 0 {
w.Header().Set(cos.HdrContentLength, strconv.Itoa(l))
w.Write([]byte(xid))
if xid != "" {
writeXid(w, xid)
}
case apc.ActXactStop:
debug.Assert(xact.IsValidKind(xargs.Kind) || xact.IsValidUUID(xargs.ID), xargs.String())
Expand Down
3 changes: 2 additions & 1 deletion ext/dsort/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ func PstartHandler(w http.ResponseWriter, r *http.Request, parsc *ParsedReq) {
return
}

w.Write([]byte(managerUUID))
w.Header().Set(cos.HdrContentLength, strconv.Itoa(len(managerUUID)))
w.Write(cos.UnsafeB(managerUUID))
}

func _handleResp(w http.ResponseWriter, r *http.Request, smap *meta.Smap, managerUUID string, responses []response) error {
Expand Down

0 comments on commit 68858f9

Please sign in to comment.