-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimization(all): Decrease allocs and responses time
- Loading branch information
Showing
11 changed files
with
164 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import ( | |
"fmt" | ||
"net" | ||
"net/http" | ||
_ "net/http/pprof" | ||
"net/url" | ||
"time" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"net/http/httptest" | ||
"strconv" | ||
"testing" | ||
"time" | ||
|
||
"github.com/darkweak/souin/cache/coalescing" | ||
"github.com/darkweak/souin/cache/service" | ||
"github.com/darkweak/souin/errors" | ||
"github.com/darkweak/souin/plugins" | ||
"github.com/darkweak/souin/plugins/souin/configuration" | ||
souintypes "github.com/darkweak/souin/plugins/souin/types" | ||
) | ||
|
||
func Benchmark_Souin_Handler(b *testing.B) { | ||
c := configuration.GetConfiguration() | ||
fmt.Printf("%+v\n", c) | ||
rc := coalescing.Initialize() | ||
retriever := souinPluginInitializerFromConfiguration(c) | ||
for i := 0; i < b.N; i++ { | ||
writer := httptest.NewRecorder() | ||
request := httptest.NewRequest(http.MethodGet, "http://domain.com/"+strconv.Itoa(i), nil) | ||
request.Header.Set("Date", time.Now().UTC().Format(time.RFC1123)) | ||
request = retriever.GetContext().Method.SetContext(request) | ||
|
||
if !plugins.CanHandle(request, retriever) { | ||
writer.Header().Set("Cache-Status", "Souin; fwd=uri-miss") | ||
return | ||
} | ||
|
||
request = retriever.GetContext().SetContext(request) | ||
callback := func(rw http.ResponseWriter, rq *http.Request, ret souintypes.SouinRetrieverResponseProperties) error { | ||
rr := service.RequestReverseProxy(rq, ret) | ||
select { | ||
case <-rq.Context().Done(): | ||
c.GetLogger().Debug("The request was canceled by the user.") | ||
return &errors.CanceledRequestContextError{} | ||
default: | ||
rr.Proxy.ServeHTTP(rw, rq) | ||
} | ||
|
||
return nil | ||
} | ||
if plugins.HasMutation(request, writer) { | ||
_ = callback(writer, request, *retriever) | ||
} | ||
retriever.SetMatchedURLFromRequest(request) | ||
coalescing.ServeResponse(writer, request, retriever, plugins.DefaultSouinPluginCallback, rc, func(_ http.ResponseWriter, _ *http.Request) error { | ||
return callback(writer, request, *retriever) | ||
}) | ||
} | ||
} |
48 changes: 20 additions & 28 deletions
48
plugins/traefik/vendor/github.com/darkweak/souin/rfc/bridge.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.