none
How to Debug the issue when the Consume R web service Test fails ? RRS feed

  • Question

  • I am Publishing the R scripts as web services in the Machine Learning server

    Given below is how I am publishing the R scripts using the mrsdeploy package  

    api <- publishService(

          'new',

          code = "new.r",

          inputs = list(a="numeric",b="numeric"),

          outputs = list(c="numeric"),

          v = "1"

        )

    Here new.r is the R script which is to be published as a web service

    In the normal scenarios I am able to consume the web service, but once I implement some functionalities in the r script I am not able to consume the web service

    Described below are the two cases when “Consume R web service capability” of the Machine learning server fails

    1. Logging

    Here I am using the log4r package to log the r code execution, given below is the code

    library(log4r)

    setwd(“C:\Rscripts\”)

    logger <- create.logger()

    logfile(logger) <- 'newscript.log'

    level(logger) <- 'DEBUG'

    c<-a*b

    debug(logger, "testing logger")

    Here I am setting the working directory to the current folder so that the log file will be generated in the same folder (The working directory seems to be dynamic. Each time the R code is executed the working directory is somewhat like : C:\Program Files\Microsoft\ML Server\R_SERVER\o16n\RServe\workdir\conn508”, and the last folder in the path, in this case conn508 changes in every run)

    )

    1. Reading the database connection parameters from the Environment variables

    I am reading  the parameters for the database connection string from the environment variables as in the code given below

    library(RODBC)

    connectionstring=sprintf('Driver=%s;server=%s ;database=%s;uid=%s;pwd=%s’,Sys.getenv("ProjectDriver"),Sys.getenv("Projectserver"),Sys.getenv("Projectdatabase"),Sys.getenv("Projectuid"),Sys.getenv("Projectpwd"))

    cn <- odbcDriverConnect(connection=connectionstring)

    referenceData<-sqlQuery(cn, 'SELECT Inflation FROM [Reference_data];')

    c<-a*b

    odbcClose(cn)

    The error message from the diagnostic run is as  given below

    ApiError (500)
    Reason: Internal Server Error
    HTTP response headers: HTTPHeaderDict({'Date': 'Wed, 04 Jul 2018 13:11:37 GMT', 'Content-Type': 'application/json', 'Server': 'Kestrel', 'Content-Length': '83', 'X-Content-Type-Options': 'nosniff', 'x-ms-request-id': '64a32a9c-e0d0-40cb-8e35-986358d7b48d'})
    HTTP response body: b'{"Link":null,"Message":"eeb952c4-fabe-4c92-80cb-bf323e82a77c","ExceptionType":null}'

    Wednesday, July 4, 2018 4:02 PM

Answers

  • Hi Mathew,

    Setwd() is not supported in a remote session and in web services for security reasons, the R shell has limited permissions and can only has write permission to the working directory. Instead, try to use the artifacts argument in publishService to define and retrieve files:

    https://docs.microsoft.com/en-us/machine-learning-server/r-reference/mrsdeploy/publishservice

    As for the other issue you are seeing, when you have the connection string hard coded, does that work for you but if using Sys.getenv() doesn't?

    If so then that is probably again because of the locked down account running the R shells that is limited in what it can do for security reasons. 

    Friday, July 6, 2018 10:07 PM

All replies

  • Hi Mathew,

    Setwd() is not supported in a remote session and in web services for security reasons, the R shell has limited permissions and can only has write permission to the working directory. Instead, try to use the artifacts argument in publishService to define and retrieve files:

    https://docs.microsoft.com/en-us/machine-learning-server/r-reference/mrsdeploy/publishservice

    As for the other issue you are seeing, when you have the connection string hard coded, does that work for you but if using Sys.getenv() doesn't?

    If so then that is probably again because of the locked down account running the R shells that is limited in what it can do for security reasons. 

    Friday, July 6, 2018 10:07 PM
  • Hi Efrat,

    Thank you for your reply. I see that you have answered my other question as well.

    I have a few more questions in my mind

    1.  I am using odbcConnect function instead of odbcDriverConnect  and using data source name to connect  to the database.The code is working fine while i am executing it inside the VM . But once i publish that code as a web service and consume it ,it is not getting connected to the database.

    I printed out the warning message using tryCatch. It is as of follows

    "consoleOutput": "<simpleWarning in RODBC::odbcDriverConnect(\"DSN=3POdsn\"): [RODBC] ERROR: state 28000, code 18456, message [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Login failed for user 'NT SERVICE\\RServe9.0.0.0'.>\r\n",

    Could it be because of any permission issue?

    If so can you propose any solution ?

    2. I am trying to implement Rcpp inside the scripts for performance improvement.But again the code is working fine while i am executing it inside the VM . While consuming the web service ,i get the below error

    Error in system(cmd, ignore.stderr = TRUE, intern = TRUE) : \n  'C:/Program' not found 


    I am getting this error 5 to 6 times after which i will get the  internal server error(as described in the previous question). Also  the consume R web service capability fails in the diagnostic run

    3.  I created dedicated session pools for each service as described:

    https://docs.microsoft.com/en-us/machine-learning-server/operationalize/how-to-create-manage-session-pools

    It didn't  improve response time

    Also i got this error while consuming the service 

     

     "success": false,
        "errorMessage": "Error in odbcQuery(channel, query, rows_at_time) : \n  'Calloc' could not allocate memory (254 of 26920 bytes)\n",

    Also the Rstudio and R inside The Vm stopped working and  were not starting up after this.

    After some time i was not even able to log into the VM

    I had to size up the  Vm to 8GB Ram(It was 4 GB earlier ) and  delete session pools to get everything back to normal

    Thank you in advance

    Thursday, July 12, 2018 2:32 PM
  • I have similar issue, wherein I am not setting any working directory in my code. Still I get Link message execption.

    https://social.technet.microsoft.com/Forums/lync/en-US/bc212cea-2bc9-4d03-b10c-0d1dc6f80032/why-mrsdeploy-web-service-call-through-curl-does-not-return-console-output?forum=MicrosoftR

    Could you please help me out?
    • Edited by Vedapragna Thursday, February 14, 2019 2:21 AM
    Thursday, February 14, 2019 2:20 AM
  • please start a new thread.
    Thursday, February 14, 2019 5:20 PM
    Owner