-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
run with GOMAXPROCS=4 go run send-static-file.go this has fairly good performance 'transaction_rate': 25974.03,
- Loading branch information
1 parent
ff8c51a
commit b57f627
Showing
2 changed files
with
68 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
import _ "embed" | ||
|
||
//go:embed static/Cargo.toml | ||
var cargoToml string | ||
|
||
var workerCount = 2 | ||
var workerPool chan struct{} | ||
|
||
func main() { | ||
// Create a buffered channel to limit the number of concurrent worker threads | ||
workerPool = make(chan struct{}, workerCount) | ||
|
||
// Handle requests using a single IO thread | ||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | ||
// Acquire a worker thread from the pool | ||
workerPool <- struct{}{} | ||
|
||
// Handle the request in a goroutine | ||
{ | ||
// Ensure the worker is released back to the pool when done | ||
defer func() { | ||
<-workerPool | ||
}() | ||
|
||
// Handle the actual request (in this case, just returning "Hello, World!") | ||
handleRequest(w, r) | ||
} | ||
}) | ||
|
||
// Start the web server on port 8080 | ||
fmt.Println("Server listening on :8080") | ||
http.ListenAndServe(":8080", nil) | ||
} | ||
|
||
func handleRequest(w http.ResponseWriter, r *http.Request) { | ||
// Simulate some work being done by the worker | ||
// fmt.Println("Processing request...") | ||
|
||
// Set the Content-Type header to plain text | ||
w.Header().Set("Content-Type", "text/plain") | ||
|
||
// Get the response string | ||
response := cargoToml | ||
|
||
// Set the Content-Length header | ||
w.Header().Set("Content-Length", fmt.Sprint(len(response))) | ||
|
||
// Write the response body | ||
fmt.Fprint(w, response) | ||
} |
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,11 @@ | ||
[workspace] | ||
members = [ | ||
"log", | ||
"shared", | ||
"roc_app", | ||
"nea", | ||
] | ||
exclude = [ | ||
"benchmarks", | ||
] | ||
resolver = "2" |