Permalink
Browse files

Significantly improved redisGet performance for large objects; improv…

…ed code inspired by the Rbig/networkspaces server of Steve Weston and Pat Shields
  • Loading branch information...
1 parent 195afdd commit fb812f348139d78f72d5a74a1c48256f4a8e4047 B. W. Lewis committed Mar 18, 2010
Showing with 23 additions and 6 deletions.
  1. +1 −1 DESCRIPTION
  2. +22 −5 R/redis-internal.R
  3. BIN inst/doc/rredis.pdf
View
@@ -1,7 +1,7 @@
Package: rredis
Type: Package
Title: Redis client for R
-Version: 1.0
+Version: 1.1
Date: 2010-01-26
Author: B. W. Lewis
Maintainer: B. W. Lewis <blewis@illposed.net>
View
@@ -64,17 +64,34 @@
dat <- tryCatch(readBin(con, 'raw', n=n),
error=function(e) .redisError(e$message))
m <- length(dat)
+ if(m>=n) return(tryCatch(unserialize(dat),
+ error=function(e) rawToChar(dat)))
+# The message was not fully recieved in one pass.
+# We allocate a list to hold incremental messages and then concatenate it.
+# This perfromance enhancement was adapted from the Rbig server package,
+# written by Steve Weston and Pat Shields.
+ rlen <- 50
+ j <- 1
+ r <- vector('list',rlen)
+ r[j] <- list(dat)
while(m<n) {
# Short read; we need to retrieve the rest of this message.
socketSelect(list(con))
- dat <- c(dat, tryCatch(readBin(con, 'raw', n=(n-m)),
- error=function (e) .redisError(e$message)))
- m <- length(dat)
+ dat <- tryCatch(readBin(con, 'raw', n=(n-m)),
+ error=function (e) .redisError(e$message))
+ j <- j + 1
+ if(j>rlen) {
+ rlen <- 2*rlen
+ length(r) <- rlen
+ }
+ r[j] <- list(dat)
+ m <- m + length(dat)
}
l <- readLines(con,n=1) # Trailing \r\n
+ length(r) <- j
# Try retrieving an R object, otherwise default to character:
- tryCatch(unserialize(dat),
- error=function(e) rawToChar(dat))
+ tryCatch(unserialize(do.call(c,r)),
+ error=function(e) rawToChar(do.call(c,r)))
},
'*' = {
vals <- NULL
View
Binary file not shown.

0 comments on commit fb812f3

Please sign in to comment.