Github user falaki commented on a diff in the pull request:

    https://github.com/apache/spark/pull/15375#discussion_r82446808
  
    --- Diff: R/pkg/R/context.R ---
    @@ -123,19 +126,48 @@ parallelize <- function(sc, coll, numSlices = 1) {
       if (numSlices > length(coll))
         numSlices <- length(coll)
     
    +  sizeLimit <- as.numeric(sparkR.conf(
    +      "spark.r.maxAllocationLimit",
    +      toString(.Machine$integer.max / 2) # Default to a safe default: 200MB
    +  ))
    +  objectSize <- object.size(coll)
    +
    +  # For large objects we make sure the size of each slice is also smaller 
than sizeLimit
    +  numSlices <- max(numSlices, ceiling(objectSize / sizeLimit))
    +
       sliceLen <- ceiling(length(coll) / numSlices)
       slices <- split(coll, rep(1: (numSlices + 1), each = 
sliceLen)[1:length(coll)])
     
       # Serialize each slice: obtain a list of raws, or a list of lists 
(slices) of
       # 2-tuples of raws
       serializedSlices <- lapply(slices, serialize, connection = NULL)
     
    -  jrdd <- callJStatic("org.apache.spark.api.r.RRDD",
    -                      "createRDDFromArray", sc, serializedSlices)
    +  # The PRC backend cannot handle arguments larger than 2GB (INT_MAX)
    +  # If serialized data is safely less than that threshold we send it over 
the PRC channel.
    +  # Otherwise, we write it to a file and send the file name
    +  if (objectSize < sizeLimit) {
    +    jrdd <- callJStatic("org.apache.spark.api.r.RRDD", 
"createRDDFromArray", sc, serializedSlices)
    +  } else {
    +    fileName <- writeToTempFile(serializedSlices)
    +    jrdd <- callJStatic(
    +      "org.apache.spark.api.r.RRDD", "createRDDFromFile", sc, fileName, 
as.integer(numSlices))
    +    file.remove(fileName)
    --- End diff --
    
    Good point. Done!


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to