我创建了一个代理人说“A”,它只是将一些庞大的数据发送给代理“B”。
代理A代码:
let largeText = "some large text (around 30kb)"
InputData_Type =
{
//some code
Body : string
}
let default_InputData =
{
//some code
Body = largeText
}
type ActorMsg =
| InItServices
| Data of InputData_Type
| UpdateList
let system = ActorSystem.Create("A")
let actRef = system.ActorSelection("akka.tcp://B@localhost:9999/user/EchoServer")
actRef.Ask(JsonConvert.SerializeObject(InItServices)).Wait()
[1..1000000]
|> List.iter(fun x ->
actRef.Tell(JsonConvert.SerializeObject(Data (default_InputData))))
let listLength = string(actRef.Ask(JsonConvert.SerializeObject(UpdateList)).Result)
printfn "length is %A" listLength
代理“B”将他收到的数据存储/维护到数据库中。
代理B代码:
try
let echoServer =
spawn system "EchoServer"
<| fun mailbox ->
let rec loop( cnt : int32 ) =
actor {
let! message = mailbox.Receive()
let sender = mailbox.Sender()
let deserializedEmailData = JsonConvert.DeserializeObject<ActorMsg> (message)
match deserializedEmailData with
| InItServices ->
sender <! ""
return! loop (0)
| Data (textData)->
// some logic to maintain list
let count = cnt + 1
return! loop (count)
| UpdateList ->
//some logic to store list
sender <! ("Length is " + cnt.ToString())
return! loop (0)
}
loop(0)
()
with
|exc ->
printfn "%A" exc
代理“A”和“B”在同一台计算机上创建,但位于不同的端口上。
我观察到,每次执行上述设置时,代理B收到的记录数量都不同。
表示如果我向代理B发送了20000条消息,则代理B实际上只接收说1600条(号码不同)消息。
上述情况到底出了什么问题?