Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201867

Improve first run time in sql r services

$
0
0

I am using an r service in SQL Server 2016 to generate a text file with a message in it. The stored procedure's output is the binary of that file. I am using the library hexView which I installed in the r of my server. The function I have created in SQL is the next.

CREATE PROCEDURE [tmp].[Message] @MessageV NVARCHAR(1000)
    ,@FileName NVARCHAR(100)
AS
BEGIN
    DECLARE @Message NVARCHAR(1000)
        ,@FName NVARCHAR(100)

    EXECUTE sp_execute_external_script @language = N'R'
        ,@script = N'
library(hexView)
File <- paste0(FName,".txt")
write.table(Message, file = File, row.names = FALSE, col.names = FALSE, quote = FALSE)
OutputDataSet <- data.frame(readRaw(File)$fileRaw)
'
        ,@params = N' @FName NVARCHAR(100)
             ,@Message NVARCHAR(1000)'
        ,@Message = @MessageV
        ,@FName = @FileName
END

And to run this function.

exec [tmp].[Message] @MessageV = 'This is a random message', @FileName = 'TextFile'

The first time I execute it, it takes around 25 secs. The immediately latter runs take only 1 sec. But if I rut it like 20 minutes after, it again takes 25 secs. I think that extra time is to start the r service inside SQL.

Is there a way or configuration to keep R services active every moment so that it would take 1 sec whenever I run it?

I have searched a lot but haven´t found anything relevant. Thanks in regards.


Viewing all articles
Browse latest Browse all 201867

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>