Parallel search query
vallerion opened this issue · 7 comments
Hi Guys!
i try querying parallel search like this:
func ActionSearchUsingStatelessMode(class, departure, arrival, date string) (*fmptbr143.FareMasterPricerTravelBoardSearchReply, error) {
messageId := strings.ToUpper(utils.RandStringBytesMaskImprSrc(22))
query := MakeSearchQuery(class, departure, arrival, date)
services := NewClient()
response, _, err := services.FareMasterPricerTravelBoardSearch(nil, messageId, query)
return response, err
}
func search(ch chan *fmptbr143.FareMasterPricerTravelBoardSearchReply) *fmptbr143.FareMasterPricerTravelBoardSearchReply {
var cabinClass = "Y"
var departureLocationId = "DEL"
var arrivalLocationId = "FRA"
date := time.Now().AddDate(0, 0, 7)
var dateStr = fmtdate.Format("DDMMYY", date)
response, _ := ActionSearchUsingStatelessMode(cabinClass, departureLocationId, arrivalLocationId, dateStr)
ch <- response
return response
}
func main() {
searchChannel := make(chan *fmptbr143.FareMasterPricerTravelBoardSearchReply, 4)
mapResults := make([]*fmptbr143.FareMasterPricerTravelBoardSearchReply, 0)
iterations := 4
for i := 0; i < iterations; i++ {
go search(searchChannel)
}
for {
select {
case searchResult := <-searchChannel:
mapResults = append(mapResults, searchResult)
}
if len(mapResults) == iterations {
close(searchChannel)
break
}
}
}
if iterations := 1
i have 7 seconds of work time, but if iterations := 4
i have 17 seconds
why it happens?
Hi @valerion1
It can be Amadeus parallel jobs handling restriction of test environment. We will try reproduce it with our configuration.
@smgladkovskiy is it possible to make from completely parallel means only golang?
Option "Amadeus parallel jobs handling" does not suit me :(
i have some amadeus connection with different config and need work with them separate
If it different connections with separate configs, you should init several clients and work with them sequently or in parallel -- as you need.
As for new version it will be something like that:
package main
import (
"log"
"github.com/tmconsulting/amadeus-golang-sdk/client"
"github.com/tmconsulting/amadeus-golang-sdk/service"
"github.com/tmconsulting/amadeus-golang-sdk/structs/commandCryptic"
)
func main() {
url1 := "https://nodeD1.test.webservices.amadeus.com/1ASIWXXXXXX"
url2 := "https://nodeD1.test.webservices.amadeus.com/1ASIWYYYYYY"
originator1 := "WSBENXXX"
originator2 := "WSBENYYY"
passwordRaw1 := "dGhlIHBhc3N3b3Jk"
passwordRaw2 := "sfdgFgWgsdfgdfgS"
officeID1 := "BRUXX1111"
officeID2 := "BRUYY1111"
var clients []*client.AmadeusClient
clients = append(clients,
client.New(client.SetURL(url1), client.SetUser(originator1), client.SetPassword(passwordRaw1), client.SetAgent(officeID1)),
client.New(client.SetURL(url2), client.SetUser(originator2), client.SetPassword(passwordRaw2), client.SetAgent(officeID2)),
)
var services []service.Service
services = append(services, service.New(clients[0]), service.New(clients[1]))
respChan := make(chan commandCryptic.Response)
errChan := make(chan error)
for _, s := range services {
go func() {
resp, err := s.CommandCryptic("AN20MAYMOWLED/ALH")
if err != nil {
errChan <- err
return
}
respChan <- *resp
}()
}
var (
responses []commandCryptic.Response
errors []error
)
for {
select {
case resp := <-respChan:
responses = append(responses, resp)
case err := <-errChan:
errors = append(errors, err)
}
if len(responses)+len(errors) == len(services) {
break
}
}
log.Printf("responses: %v\n", responses)
}
@smgladkovskiy thanks! it seems that work
i interesting: how much you get response from amadeus to search (masterPricer...)? I got something for about 2-3 seconds
I got something for about 2-3 seconds
It is good enough time for search response. In production it will be 1-2 secs.
For some reasons it is much longer to book or issue sometimes. :)
@smgladkovskiy thanks for answers!
Good! I'm closing the issue. If you'll have some question – feel free to ask.