Documentation
¶
Index ¶
- func Upgrade(w http.ResponseWriter, r *http.Request) (*websocket.Conn, error)
- type Client
- type SearchRequest
- type Server
- func (server *Server) AddClient(client *Client)
- func (server *Server) AddSlave(slave *Client)
- func (server *Server) AddToQueue(request *SearchRequest)
- func (server *Server) BroadcastConfiguration()
- func (server *Server) BroadcastQueueStatus()
- func (server *Server) BroadcastSlaveStatus()
- func (server *Server) Found(request *SearchRequest, result string)
- func (server *Server) PrintConfiguration(client *Client)
- func (server *Server) RemoveClient(client *Client)
- func (server *Server) RemoveSlave(slave *Client)
- func (server *Server) Scale(number int) error
- func (server *Server) SetAutoScale(isAutoScale bool)
- func (server *Server) SetMaxSearch(maxSearch string)
- func (server *Server) SetMaxSlavesPerRequest(maxSlavesPerRequest int)
- func (server *Server) Start()
- func (server *Server) StopAll()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type SearchRequest ¶
type SearchRequest struct { Hash string // Hash that is being searched Slaves map[*Client]bool // Slaves that are working one resolving the hash Client *Client // Client that made the request Result string // Decoded hash RequestedAt time.Time // Time when the request has been received StartedAt time.Time // Time when the slaves started to work on this request EndedAt time.Time // Time when the result has been found }
func NewSearchRequest ¶
func NewSearchRequest(hash string, client *Client) *SearchRequest
NewSearchRequest initialize a SearchRequest object with default values and given parameters
func (*SearchRequest) FormatResponse ¶
func (searchRequest *SearchRequest) FormatResponse() string
FormatResponse format the object in order to be returned in a response to a Client
type Server ¶
type Server struct { Slaves map[*Client]bool // List of Clients that are slaves AvailableSlaves map[*Client]bool // List of slaves that are available for work Clients map[*Client]bool // List of connected Clients Queue *list.List // Queue containing the SearchRequest that are waiting to be resolved Searching map[*SearchRequest]bool // List of SearchRequest that are being searched MaxSearch string // The limit at which the message would be, can only be 9 from 2 to 8 times MaxSlavesPerRequest int // Maximum of slaves that will be dedicated to a SearchRequest SlavesCount int // Number of slaves that we want (not equals to len(Slaves) if we are currently scaling) AutoScale bool // Tells whether the app should scale the slave automatically depending on the queue // contains filtered or unexported fields }
func NewServer ¶
func NewServer(client *redis.Client) *Server
NewServer initialized a Server object with default values and parameters
func (*Server) AddSlave ¶
AddSlave adds a slave to the Slaves list and the AvailableSlaves list, and calls BroadcastSlaveStatus
func (*Server) AddToQueue ¶
func (server *Server) AddToQueue(request *SearchRequest)
AddToQueue adds a search request to the queue and calls BroadcastQueueStatus
func (*Server) BroadcastConfiguration ¶
func (server *Server) BroadcastConfiguration()
BroadcastConfiguration sends to all Clients the current configuration in the format: max-search MaxSearch slaves SlavesCount numberOfSlavesNotWorking numberOfSlavesWorking max-slaves-per-request MaxSlavesPerRequest auto-scale true|false
func (*Server) BroadcastQueueStatus ¶
func (server *Server) BroadcastQueueStatus()
BroadcastQueueStatus sends to all Clients the current status of the queue in the format: queue numberOfRequestInQueue numberOfRequestBeingHandled
func (*Server) BroadcastSlaveStatus ¶
func (server *Server) BroadcastSlaveStatus()
BroadcastSlaveStatus sends to all Clients the current status of slaves in the format: slaves SlavesCount numberOfSlavesNotWorking numberOfSlavesWorking
func (*Server) Found ¶
func (server *Server) Found(request *SearchRequest, result string)
Found called when a slave has found the result of a SearchRequest, it then sends the result to the client and tells the other Slaves that were working on the SearchRequest to stop
func (*Server) PrintConfiguration ¶
PrintConfiguration sends the current configuration to a client in the format max-search MaxSearch slaves SlavesCount numberOfSlavesNotWorking numberOfSlavesWorking max-slaves-per-request MaxSlavesPerRequest auto-scale true|false
func (*Server) RemoveClient ¶
RemoveClient removes a client from the Clients list
func (*Server) RemoveSlave ¶
RemoveSlave removes a slave from the Slaves and the AvailableSlaves list, and calls BroadcastSlaveStatus
func (*Server) Scale ¶
Scale choose the number of Slaves that we want in our application, must be between 0 and 16 for performance reason
func (*Server) SetAutoScale ¶
SetAutoScale set if the server should scale automatically the slaves or not
func (*Server) SetMaxSearch ¶
SetMaxSearch set the MaxSearch parameter, it defines to what limit the slaves must search the word, it can only be 9 from 2 to 8 times
func (*Server) SetMaxSlavesPerRequest ¶
SetMaxSlavesPerRequest set the maximum number of slaves that we assign to a SearchRequest