【发布时间】:2017-01-19 19:15:29
【问题描述】:
我在这里询问了如何制作一直发送数据的 TCP 服务器:Julia TCP select,它工作得很好。我现在有新问题,所以我想开始新的对话。
所以 Sender 有时会向服务器 1 发送一些内容,服务器 1 读取它并更新要发送到服务器 2 的内容,然后服务器 2 计算数字并与 C 程序通信。
这是我的服务器 1 代码:
notwaiting = true
message = zeros(10,14)
server = listen(5001)
connection = connect(5003)
while true
if notwaiting
notwaiting = false
# Runs accept async (does not block the main thread)
@async begin
sock = accept(server)
reply= read(sock, Float64, 11)
message[:,convert(Int64,reply[1])] = reply[2:11]
write(connection,reshape(message,140))
global notwaiting = true
end
end
write(connection,reshape(message,140))
if message[1,1] == -1.0
close(connection)
close(server)
break
end
sleep(0.01) # slow down the loop
end
发件人是:
Connection2= connect(5001)
message = [2.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0]
write(Connection2,message)
close(Connection2)
而服务器2是这样的:
function Server2_connection()
println("Waiting for connection")
server2 = listen(5003)
conn_2 = accept(server2)
while isopen(conn_2)
try
message_server2 = round(read(conn_2,Float64,140),3)
ins_matrix = reshape(message_server2[1:140],10,14)
catch e
println("caught an error $e")
break
end
end
println("Connection closed")
close(conn)
close(server)
end
问题是所有东西加在一起真的很重。我的意思是我可以从发件人那里发送 2 条消息,但一切都运行得很慢。我可以运行整个事情 10-15 秒,然后它就冻结了。所有的连接都有效,但速度很慢。我的问题是我错过了什么或有什么让服务器真的很慢?我怎样才能更好地编码?
【问题讨论】:
-
您没有使用Julia's parallel tools 进行远程呼叫/远程评估的任何特殊原因?
-
我无法重现缓慢或冻结(运行测试约 5 分钟并发送 10 条消息)。我对所有在 Windows 系统上运行 Julia 0.5+rc3 的程序进行了测试,没有出现缓慢的情况。甚至将 server2 移动到 Mac(通过 wi-fi 网络连接)服务器 1 和 2 运行正常。也许是版本或环境的问题? (例如:操作系统、硬件、网络……)
-
你是什么意思?你能更具体地解释一下你的意思吗@FelipeLema
-
我正在使用 Julia 0.4.6 和 atom 编辑器。很好,它可以工作。 @Gomiero
-
@pinq 哦,没关系,我以为远程服务器是需要 C 程序的 julia 服务器。现在我明白我错了。