-
Notifications
You must be signed in to change notification settings - Fork 53
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
15 changed files
with
172 additions
and
134 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
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,54 @@ | ||
package main | ||
|
||
import ( | ||
"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() | ||
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) | ||
}) | ||
} | ||
} |
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
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.
Oops, something went wrong.