Comments (2)
@cloverkits, I need clarification on your goals and objectives. I will try to provide facts. Typically, goroutine gets used where concurrent/parallelism is required to optimize overall processing time and efficiency.
I think the above goroutine example wouldn't provide valuable information on time measurement.
Have you tried the Go default HTTP client with your goroutine example?
from resty.
@jeevatkm yep! Default HTTP client maybe have something wrong in goroutine. In your words "concurrent/parallelism is required to optimize overall processing time" which is my case. I need reads multiple objects in parallel from one server multi interfaces.
example code
package main
import (
"io"
"log"
"net/http"
"sync"
"time"
)
func main() {
wg := sync.WaitGroup{}
for i := 0; i < 50; i++ {
wg.Add(1)
go func() {
defer wg.Done()
startAt := time.Now()
resp, err := http.Get("https://www.baidu.com")
if err != nil {
log.Println(err)
}
defer resp.Body.Close()
log.Println("latency:", time.Since(startAt))
_, err = io.ReadAll(resp.Body)
if err != nil {
log.Println(err)
}
}()
}
wg.Wait()
}
result
2023/09/25 10:12:23 latency: 69.907033ms
2023/09/25 10:12:23 latency: 69.614386ms
2023/09/25 10:12:23 latency: 70.939928ms
2023/09/25 10:12:23 latency: 70.62763ms
2023/09/25 10:12:23 latency: 71.418996ms
2023/09/25 10:12:23 latency: 72.425473ms
2023/09/25 10:12:23 latency: 78.597691ms
2023/09/25 10:12:23 latency: 81.947911ms
2023/09/25 10:12:23 latency: 82.902086ms
2023/09/25 10:12:23 latency: 84.898575ms
2023/09/25 10:12:23 latency: 84.801553ms
2023/09/25 10:12:23 latency: 84.496353ms
2023/09/25 10:12:23 latency: 85.732495ms
2023/09/25 10:12:23 latency: 85.642949ms
2023/09/25 10:12:23 latency: 85.952062ms
2023/09/25 10:12:23 latency: 86.141165ms
2023/09/25 10:12:23 latency: 87.003269ms
2023/09/25 10:12:23 latency: 87.436695ms
2023/09/25 10:12:23 latency: 91.543479ms
2023/09/25 10:12:23 latency: 91.84506ms
2023/09/25 10:12:23 latency: 92.977854ms
2023/09/25 10:12:23 latency: 93.429503ms
2023/09/25 10:12:23 latency: 94.71919ms
2023/09/25 10:12:23 latency: 95.130987ms
2023/09/25 10:12:23 latency: 97.990181ms
2023/09/25 10:12:23 latency: 98.086186ms
2023/09/25 10:12:23 latency: 98.242818ms
2023/09/25 10:12:23 latency: 98.315098ms
2023/09/25 10:12:23 latency: 98.920861ms
2023/09/25 10:12:23 latency: 99.129425ms
2023/09/25 10:12:23 latency: 100.425497ms
2023/09/25 10:12:23 latency: 101.000571ms
2023/09/25 10:12:23 latency: 101.15033ms
2023/09/25 10:12:23 latency: 100.735866ms
2023/09/25 10:12:23 latency: 101.528584ms
2023/09/25 10:12:23 latency: 101.650535ms
2023/09/25 10:12:23 latency: 101.478554ms
2023/09/25 10:12:23 latency: 104.253945ms
2023/09/25 10:12:23 latency: 104.981183ms
2023/09/25 10:12:23 latency: 105.334097ms
2023/09/25 10:12:23 latency: 105.663269ms
2023/09/25 10:12:23 latency: 106.390947ms
2023/09/25 10:12:23 latency: 106.30004ms
2023/09/25 10:12:23 latency: 107.450104ms
2023/09/25 10:12:23 latency: 110.235126ms
2023/09/25 10:12:23 latency: 110.161177ms
2023/09/25 10:12:23 latency: 110.386901ms
2023/09/25 10:12:23 latency: 110.360874ms
2023/09/25 10:12:23 latency: 110.623886ms
2023/09/25 10:12:23 latency: 111.314326ms
from resty.
Related Issues (20)
- compilation fails with bazel in resty 2.8 HOT 4
- .SetTimeout() option breaks functionality, results in showing the duration of HTTP request wrong. HOT 5
- Add clone method in `Request`
- Unable to test Body() due to unexported variable body HOT 3
- Setting context for all request? HOT 6
- Problem with a client requesting a TCP service HOT 4
- [BUG] DigestAuth with SetBody will be 'http: ContentLength=54 with Body length 0' HOT 3
- SetResult replaces nested struct with a map inside a map HOT 2
- Resty client global variable HOT 2
- parseResponseBody > Unmarshalc cannot unmarshal string into Go value of type map[string]interface {}
- DATA RACE in resty's middleware (go-resty/resty/v2.releaseBuffer()) HOT 2
- What's the idiomatic way of changing proxies for the client? HOT 3
- Add support for go-logr/logr on resty HOT 4
- Is the `SetTimeout()` respected by the default context?
- Request body is written multiple times HOT 2
- Result value has been set and parsed correctly and the request returns successfully, the correct address cannot be recognized HOT 2
- support OnBeforeResponse HOT 1
- setTimeout does not take effect HOT 2
- memory leak when response is too large HOT 2
- SetRetryCount() on request? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from resty.