Coder Social home page Coder Social logo

Comments (12)

domesticmouse avatar domesticmouse commented on May 14, 2024 1

Hey @broady @samthor, any ideas on how to fix this behaviour? At a guess, this is probably caused by the rate limiter...

from google-maps-services-go.

domesticmouse avatar domesticmouse commented on May 14, 2024 1

I don't have tests to confirm rate limiting. I'll be migrating to golang.org/x/time/rate within the next couple of weeks. Thanks!

from google-maps-services-go.

AlphaWong avatar AlphaWong commented on May 14, 2024
Dropped 1 node (cum <= 0.02s)
      flat  flat%   sum%        cum   cum%
     1.84s 46.00% 46.00%      1.84s 46.00%  github.com/google-map-geo-benchmark.NewGoogleMapInstance
     1.18s 29.50% 75.50%      1.18s 29.50%  github.com/google-map-geo-benchmark.BenchmarkMartinlindheGoogleMapInstance
     0.96s 24.00% 99.50%      2.80s 70.00%  github.com/google-map-geo-benchmark.BenchmarkGoogleMapInstance

My benchmark code

package main

import (
	"testing"

	geo "github.com/martinlindhe/google-geolocate"
	"googlemaps.github.io/maps"
)

var (
	googleMapClient *maps.Client
	g               *geo.GoogleGeo
)

func NewGoogleMapInstance() {
	if nil == googleMapClient {
		c, _ := maps.NewClient(maps.WithAPIKey("Insert-API-Key-Here"))
		googleMapClient = c
	}
}

func NewMartinlindheGoogleMapInstance() {
	if nil == g {
		client := geo.NewGoogleGeo("api-key")
		g = client
	}
}

func BenchmarkGoogleMapInstance(b *testing.B) {
	for i := 0; i < b.N; i++ {
		NewGoogleMapInstance()
	}
}

func BenchmarkMartinlindheGoogleMapInstance(b *testing.B) {
	for i := 0; i < b.N; i++ {
		NewMartinlindheGoogleMapInstance()
	}
}

Run

go test -benchmem -bench=. -cpuprofile=cpu.out

Result

goos: linux
goarch: amd64
pkg: github.com/google-map-geo-benchmark
BenchmarkGoogleMapInstance-4               	1000000000	         2.45 ns/op	       0 B/op	       0 allocs/op
BenchmarkMartinlindheGoogleMapInstance-4   	2000000000	         0.53 ns/op	       0 B/op	       0 allocs/op
PASS
ok  	github.com/google-map-geo-benchmark	3.840s

from google-maps-services-go.

AlphaWong avatar AlphaWong commented on May 14, 2024

@domesticmouse
U are right after I remove the code

	if c.requestsPerSecond > 0 {
		// Implement a bursty rate limiter.
		// Allow up to 1 second worth of requests to be made at once.
		c.rateLimiter = make(chan int, c.requestsPerSecond)
		// Prefill rateLimiter with 1 seconds worth of requests.
		for i := 0; i < c.requestsPerSecond; i++ {
			c.rateLimiter <- 1
		}
		go func() {
			// Wait a second for pre-filled quota to drain
			time.Sleep(time.Second)
			// Then, refill rateLimiter continuously
			for range time.Tick(time.Second / time.Duration(c.requestsPerSecond)) {
				c.rateLimiter <- 1
			}
		}()
}

The cpu drop down to 0 % again.

from google-maps-services-go.

broady avatar broady commented on May 14, 2024

Yeah, NewClient really shouldn't be doing that.

A robust rate limiter is available at golang.org/x/time/rate. This package should probably just use (or copy) that one.

from google-maps-services-go.

AlphaWong avatar AlphaWong commented on May 14, 2024

Hi, do exiting test case cover rate limit logic ?

As when I run go test ./... seems all of it has been passed in my local environment.

It is necessary for me to create a real client to call the library > rate limit in order to test the rate limit part ?

from google-maps-services-go.

AlphaWong avatar AlphaWong commented on May 14, 2024

@domesticmouse thank you very much !!!!!

from google-maps-services-go.

AngelTs avatar AngelTs commented on May 14, 2024

When using Google api in IE11, Edge or Firefox, the CPU is 30-50% + GPU 2-5%
Only in Chrome its work OK

from google-maps-services-go.

domesticmouse avatar domesticmouse commented on May 14, 2024

@AngelTs I doubt that a server side rate limiter would cause differentiated behavior between Chrome and IE11, Edge and Firefox. I'm guessing you are describing a Google Maps for JavaScript issue?

from google-maps-services-go.

AngelTs avatar AngelTs commented on May 14, 2024

Update: I found the BUG:
the freezing on IE11 and high usage of CPU in Edge and Firefox is occurred only if create table with many columns and rows (> of height of google map) and this table is normal but NOT responsive!.
Tested with default example https://developers.google.com/maps/documentation/javascript/examples/infowindow-simple
plus normal table with 30 columns + 5 rows
[I want reward for this bug :):):)]

from google-maps-services-go.

domesticmouse avatar domesticmouse commented on May 14, 2024

Hey @AngelTs, you'll need to report it on the correct bug tracker for a start. Try filing it here instead. This bug tracker is for the Go client library for the Google Maps Web Services. Thanks!

from google-maps-services-go.

AlphaWong avatar AlphaWong commented on May 14, 2024

Thx man

from google-maps-services-go.

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.