Goroutines on Individual servers [closed] - go

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I am working on an application in Go in which I am using goroutines. Each of which connects to third party servers and collects data which is then processed and used in application.
Just as an example :
for _, apiInfo := range apiInfoList {
go external1.GetResponse(searchReq)
go external2.GetResponse(searchReq)
go external3.GetResponse(searchReq)
}
Now these goroutines are running on single server.
Is it possible to run goroutines on individual servers. ?
In my case can I run it on three different servers?

A goroutine (it's a single word) by its very definition is a light-weight thread of execution inside a single process managed by an operating system's kernel.
Hence the question as stated has no sense: if you want a task to be carried out by a separate process you do not need a goroutine — you need a separate process (no matter whether it is to be run on the same machine or not).
To exchange data between separate processes, you need to use some form of IPC.

Related

Golang Ctx WIthTimeOut in Clojure [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
In clojure concurrency, I would like the thread that I spawn kill itself if it take to long to do it's task, similar to what Golang ctx withtimeout provide. how should i do it?
Mind you I dont have any knowledge of java thread.
You can't kill a Java thread cleanly, so people usually write very long-running threads to check a flag occasionally, and keep working only if appropriate.
On the other hand, a thread's client can stop waiting for an answer. If you start the thread with future, you can use the timeout parameter on deref at https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/deref, or check on it with future-done?.
When you have a lot of async stuff going on, the better Go-like algebra in Clojure's core.async library can be helpful (https://clojure.github.io/core.async/) as an alternative to raw Java threads.
never mind, apparently there is something called future and promise..

Is there visibility issue in golang? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
For example, if I update a global variable in one goroutine, then read the variable in another goroutine, can I get the newest value?
Another question is, can "atomic.Load*" and "atomic.Store*" ensure visibility?
Without explicit synchronization between goroutines, there is no guarantee that you will see the latest value of a shared variable. The Go memory model describes this:
https://golang.org/ref/mem
Atomic load/store have memory barriers, and they do guarantee you will see the latest value, though the Go memory model does not explicitly state this.

Implementing redis in go [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am trying implement redis basic functionality like below in Go.
GET
SET
ZADD
ZCARD
ZCOUNT
ZRANGE
SAVE
If you want to implement a Go server offering some Redis features, it is quite easy. You need to decide about the goroutine model, then implement/reuse some data structures (map and skiplist), then implement the Redis protocol (which is simple enough).
I would suggest a goroutine model with 2 goroutines per client connection, plus one goroutine to implement the Redis engine and manage the data structures. The benefit of this model is you can easily support pipelining and the atomicity property of Redis commands without any explicit locking. This model is well adapted if you want to later extend the scope by supporting blocking commands (such as the ones useful for queues).
Now, if you also want to mimic the same exact Redis behavior, this is more complex. Especially, saving the data in background leveraging the OS copy-on-write mechanism will be difficult with Go (since forking does not work). For a memory database, foreground saving is always easy. Background saving is extremely difficult.
You may also want to have a look at the following attempts, and simplify/enrich them to match your goals:
https://github.com/siddontang/ledisdb
https://github.com/felixge/go-redis
https://github.com/docker/go-redis-server

how do you crash a machine with infinite loop in ruby? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
how do you crash a machine with infinite loop in ruby?
An infinite loop alone can't crash a "machine", unless it gets 100% CPU time (which no sane OS will allow).
You can create an infinite loop which will eat up memory without letting it be garbage collected, but this will just crash the current process.
You could instead create processes, which create other processes recursively (a fork bomb). This will manage to slow down and eventually crash a "machine", but any sane server will have a limitation on how many processes a user can spawn.
In Linux (or equivalant), you can keep opening files and never close them - at some point - you will start seeing "Too many open files" error - this can also hinder opening of new network connections. This can happen if one has not reviewed open file limits on the system and working with default settings.
You can also keep creating files with lot of data in the OS partition, and fill up the disk space which can eventually lead to unresponsive system. This can happen if you application creates too many log entries and you forget to rotate the files.

what are windows synchronization routines other than critical_section? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am reading through the msdn articles about windows synchronization. It is really good & thorough material. At the same time is very time consuming. I am more interested in a quick comprehensive guide on the same topic. Any pointers?
This is a list of the concepts that I use in my native (unmanaged, Win32) application. I've added some relevant function names between parenthesis):
CriticalSection (InitializeCriticalSection, TryEnterCriticalSection, LeaveCriticalSection, ...)
Mutex (CreateMutex, WaitForsingleObject, ReleaseMutex, CloseHandle, ...)
Semaphore (CreateSemaphore, WaitForSingleObject, ReleaseSemaphore, CloseHandle, ...)
Event (CreateEvent, SetEvent, ResetEvent, WaitForSingleObject, CloseHandle, ...)
Besides these you could also use a file to implement locking (e.g. between processes running on different machines):
Simply create the file using CreateFile, use FILE_FLAG_DELETE_ON_CLOSE, and don't specify any of the sharing flags.
If a process already created the file, the CreateFile will fail.
To unlock, close the file using CloseHandle.
This might be a good starting point:
Synchronization Functions: http://msdn.microsoft.com/en-us/library/ms686360%28v=VS.85%29.aspx

Resources