Hi Christian,
All my previous packages for RBaseX were based on using a blocking socket. Every attempt to use a non-blocking socket failed because I couldn't authenticate. In R each read-operation on a blocking socket uses a timeout of at least 1 second. Consequence was that executing 53 tests on my pacakge took at least 116 seconds on my machine.
I finally managed to use a non-blocking socket. Execution of the same tests now take 3.8 seconds. It showed that the crucial needed step was to introduce a sleep/wait between sending the authentication nonce and checking the statusbyte:
code <- md5(paste(md5(code), nonce, sep = "")) %>% charToRaw() # send username + code auth <- c(charToRaw(username), as.raw(0x00), code, as.raw(0x00)) writeBin(auth, private$conn) ==> Sys.sleep(.1) Accepted <- readBin(conn, what = "raw", n = 1) ==0
My knowledge of working with sockets is limited so maybe you can answer my question. Does the need of using a sleep means I need to fix a bug in the R code or should I use a setting in BaseX that takes into account the required delay?
Ben Engbers
Hi Ben,
I assume this challenge needs to be tackled in the R realm: If the Java client is used, no sleep is required at all.
Hope this helps, Christian
On Wed, Dec 8, 2021 at 12:53 PM Ben Engbers Ben.Engbers@be-logical.nl wrote:
Hi Christian,
All my previous packages for RBaseX were based on using a blocking socket. Every attempt to use a non-blocking socket failed because I couldn't authenticate. In R each read-operation on a blocking socket uses a timeout of at least 1 second. Consequence was that executing 53 tests on my pacakge took at least 116 seconds on my machine.
I finally managed to use a non-blocking socket. Execution of the same tests now take 3.8 seconds. It showed that the crucial needed step was to introduce a sleep/wait between sending the authentication nonce and checking the statusbyte:
code <- md5(paste(md5(code), nonce, sep = "")) %>% charToRaw() # send username + code auth <- c(charToRaw(username), as.raw(0x00), code, as.raw(0x00)) writeBin(auth, private$conn)
==> Sys.sleep(.1) Accepted <- readBin(conn, what = "raw", n = 1) ==0
My knowledge of working with sockets is limited so maybe you can answer my question. Does the need of using a sleep means I need to fix a bug in the R code or should I use a setting in BaseX that takes into account the required delay?
Ben Engbers
Hi Christian,
As far as I now understand, a socketConnection is not a single connection but in fact a pool of connections. And I believe this is language-independent. In R, Tthe command socketSelect(list(<connection>)) waits for the first of several socket connections and server sockets to become available. After inserting this command in my code, there is no need anymore to explicitly insert a sleep. Execution-time for all the results has been reduced to 1.4 seconds instead of 120 as before.
Now I can really start using RbaseX!
Ben
Op 08-12-2021 om 12:55 schreef Christian Grün:
Hi Ben,
I assume this challenge needs to be tackled in the R realm: If the Java client is used, no sleep is required at all.
Hope this helps, Christian
basex-talk@mailman.uni-konstanz.de