【问题标题】:How to trace an error most likely due to server call?如何跟踪最有可能是由于服务器调用引起的错误?
【发布时间】:2018-06-04 11:42:32
【问题描述】:

如果您在C:/OSRM_API5/ 中安装了 OSRM API 版本 5,则下面可重现示例中的以下循环会生成错误(或多或少是随机的。上次我运行代码是在 i=17 时。我们运行了在 3 台不同的笔记本电脑上的代码并获得以下不同的消息:

viaroute5 中的错误(locs$x[i], locs$y[i], locs$x[j], locs$y[j]) :
找不到对象“res”另外:警告消息:1:在 文件(con,“r”):InternetOpenUrl 失败:'Die Serververbindung konnte nicht hergestellt werden。 2:在值[3L]:达到 经过时间限制 [cpu=1s, elapsed=1s]

options() 中的错误:已达到已用时间限制另外:警告 消息:在文件中(con,“r”):InternetOpenUrl 失败:'死 Serververbindung konnte nicht hergestellt werden.'

粘贴错误("Error in", dcall, ":") : 已达到时间限制

最初我们认为是setWinProgressBar,但现在错误仍然存​​在,尽管setWinProgressBar 已被注释掉。

有人知道发生了什么或如何追踪此错误吗?

viaroute5 <- function(lat1, lng1, lat2, lng2, instructions) {
  address <- "http://localhost:5000"
  request <- paste(address, "/route/v1/driving/",
                     lng1, ",", lat1, ";", lng2, ",", lat2,
                     "?overview=false", sep = "", NULL)

  R.utils::withTimeout({
    repeat {
      res <- try(
        route <- rjson::fromJSON(
          file = request))
      if (class(res) != "try-error") {
        if (!is.null(res)) {
          break
        } else {
          stop("???")
        }
      }
    }
  }, timeout = 1, onTimeout = "warning")

  if (res$code == "Ok") {
      return(res$routes[[1]]$duration)
    } else {
      t_guess <- 16*60
      warning("Route not found: ", paste(lat1, lng1, lat2, lng2, collapse = ", "),
              ". Time set to ", t_guess/60 , " min.")
  }
}


n <- 1e3 # ................................... if set to 10, everything is fine!
locs <- data.frame(x = c(47.424536, 47.427061),
                   y = c(9.365103, 9.365062), stringsAsFactors = FALSE)

# pb <- winProgressBar(title = "Test",
#                      label = "0% done", min=0, max=100, initial=0)
wd <- getwd()
setwd("C:/OSRM_API5")
shell(paste0("osrm-routed ", "switzerland-latest.osrm", " >nul 2>nul"), wait = F)
Sys.sleep(3) # OSRM needs time
setwd(wd)
for (i in 1:n) {
  print(i)
  # info <- paste0("done ", round(i/nrow(locs)*100, 1), "%")
  # setWinProgressBar(pb, i/nrow(locs)*100, label = info)
  for (j in 1:n) {
    viaroute5(locs$x[1], locs$y[1], locs$x[2], locs$y[2])
  }
}
shell("TaskKill /F /IM osrm-routed.exe >nul 2>nul")
# close(pb)

评论 1
如果我用一些微不足道的东西替换viaroute5(locs$x[1], locs$y[1], locs$x[2], locs$y[2]),例如i+j 错误消失了(当然)。

评论 2 当我从 `i=17 开始时,它看起来像

[1] 17
Error in file(con, "r") : reached elapsed time limit
Error in file(con, "r") : reached elapsed time limit
[1] 18
[1] 19
[1] 20
[1] 21
[1] 22
[1] 23
[1] 24
Error in readLines(file, warn = FALSE) : reached elapsed time limit
[1] 25
[1] 26
[1] 27
[1] 28
[1] 29
[1] 30
[1] 31
[1] 32
[1] 33
[1] 34
Error in viaroute5(locs$x[1], locs$y[1], locs$x[2], locs$y[2]) : 
  object 'res' not found
In addition: Warning messages:
1: In file(con, "r") :
  InternetOpenUrl failed: 'Die Serververbindung konnte nicht hergestellt werden.'
2: In value[[3L]](cond) : reached elapsed time limit [cpu=1s, elapsed=1s]

【问题讨论】:

    标签: r


    【解决方案1】:

    我认为这是由于请求的速度比 OSRM 处理它们的速度快。这会导致完整的 OSRM 请求队列,并最终导致令人毛骨悚然的错误消息。部分解释见here

    使用来自 github 的最新 OSRMR 版本,您应该不会再收到此类错误。在v0.1.31 中,我更改了OSRMR 包的viaroute 函数,通过添加一个新的可选参数timeout 来解决这个问题。 timeout 默认情况下将 viaroute 调用休眠 1 毫秒。 timeout也可以调整。

    您可以从 github 安装最新的 OSRMR 版本:

    devtools::install_github("ims-fhs/osrmr")
    

    以下可重现的示例对我有用:

    osrmr::run_server("switzerland-latest", "C:/OSRM_API5")
    
    n <- 1e3
    locs <- data.frame(x = c(47.424536, 47.427061),
                       y = c(9.365103, 9.365062), stringsAsFactors = FALSE)
    
    for (i in 1:n) {
      print(i)
      for (j in 1:n) {
        osrmr::viaroute(locs$x[1], locs$y[1], locs$x[2], locs$y[2], instructions = FALSE, api_version = 5, localhost = TRUE, timeout = 0.001)
      }
    }
    osrmr::quit_server()
    

    【讨论】:

      猜你喜欢
      • 2012-01-10
      • 1970-01-01
      • 2018-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-01
      • 1970-01-01
      相关资源
      最近更新 更多