Sobes.tech

Implement the Queue method

Middle+
Яндекс
1

What does an empty interface in Go look like and what happens if you pass it as a function argument?

Senior
ClearWay
1

How exactly was the process of loading or building this data structured?

Senior
ClearWay
1

What happens to the program if a panic occurs in a separate goroutine?

Senior
ClearWay
1

// code snippet for the best() function // with error handling for no backend available

Middle
Яндекс
1

Imagine that the API you wrote with your team suddenly started responding five times slower. What would you start checking and how would you begin the investigation?

Middle
2gis2gis
1

type Response interface{} type Backend interface { Invoke(ctx context.Context, req Request) (Response, error) } var _ Backend = &BackendImpl{} // addr contains the ip:port of a specific instance func NewBackend(addr string) *BackendImpl type backentry struct { backend Backend inflight int64 } type Balancer struct { backends []*backentry mu *sync.Mutex } var _ Backend = &Balancer{} // addrs contain the addresses of all balancable instances func NewBalancer(addrs []string) *Balancer { data := make([]*backentry,len(addrs)) for i,addr := range addrs{ data[i] = &backentry{ backend: NewBackend(addr), inflight: 0, } } return &Balancer{backends:data} } func(b *Balancer)Invoke(ctx context.Context, req Request) (Response, error){ b.mu.Lock() entry := b.best() atomic.AddInt64(&entry.inflight,1) b.mu.Unlock() defer atomic.AddInt64(&entry.inflight,-1) return entry.backend.Invoke(ctx,req) } func(b *Balancer) best() *backentry{ var best *backentry for _,entry := b.backends{ if best == nil || atomic.LoadInt64(&entry.inflight) < atomic.LoadInt64(&best.inflight){ best = entry } } return best }

Middle
Яндекс
0

What are the types of synchronous and asynchronous inter-service interactions, what tools are used for them, and what have you used in practice?

Senior
ClearWay
0

// code snippet for the best() function // with error handling for no backend available

Middle
Яндекс
0

Why are transactions needed in a database and what problems do they solve?

Middle
2gis2gis
0

How do you enrich errors with context in Go and pass them further while preserving the original error?

Senior
ClearWay
0

How does sync.Map differ from map plus mutex?

Senior
ООО Вес Медиа
0

What happens when a client cancels an HTTP request?

Senior
ООО Вес Медиа
0

How active is your job search: how many interviews and companies are you communicating with?

Middle
2gis2gis
0

What are the differences between gRPC and REST?

Senior
ClearWay
0

// code snippet for the best() function // with error handling for no backend available

Middle
Яндекс
0

// code snippet for the best() function // with error handling for no backend available

Middle
Яндекс
0

How does sync.Mutex differ from sync.RWMutex?

Senior
ООО Вес Медиа
0

What happens to the entire program if a panic occurs in the HTTP handler?

Senior
ClearWay
0

Describe the process of analyzing and optimizing a long SQL query.

Senior
ClearWay
0
/420