Giter Site home page Giter Site logo

Comments (2)

jeevatkm avatar jeevatkm commented on May 22, 2024

@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.

cloverkits avatar cloverkits commented on May 22, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.