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

    https://github.com/apache/spark/pull/4417#discussion_r31484624
  
    --- Diff: examples/src/main/python/broadcast.py ---
    @@ -0,0 +1,60 @@
    +#
    +# Licensed to the Apache Software Foundation (ASF) under one or more
    +# contributor license agreements.  See the NOTICE file distributed with
    +# this work for additional information regarding copyright ownership.
    +# The ASF licenses this file to You under the Apache License, Version 2.0
    +# (the "License"); you may not use this file except in compliance with
    +# the License.  You may obtain a copy of the License at
    +#
    +#    http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing, software
    +# distributed under the License is distributed on an "AS IS" BASIS,
    +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +# See the License for the specific language governing permissions and
    +# limitations under the License.
    +#
    +
    +import sys
    +import time
    +from operator import add
    +from pyspark import SparkContext, SparkConf
    +
    +# Broadcast variables allow the programmer to keep a read-only variable
    +# cached on each machine rather than  shipping a copy of it with tasks.
    +# Spark also attempts to distribute broadcast variables using efficient
    +# broadcast algorithms to reduce communication cost.
    +
    +# Usage: BroadcastTest [slices] [numElem] [broadcastAlgo] [blockSize]
    +
    +if __name__ == "__main__":
    +    slices = int(sys.argv[0]) if len(sys.argv) > 1 else 1
    +    num = int(sys.argv[1]) if len(sys.argv) > 2 else 1000000
    +    bcName = sys.argv[2] if len(sys.argv) > 3 else "Http"
    +    blockSize = sys.argv[3] if len(sys.argv) > 4 else "4092"
    +
    +    conf = SparkConf().setAppName("Broadcast Test") \
    +                      .setMaster("local") \
    +                      .set("spark.broadcast.factory", 
"org.apache.spark.broadcast.%sBroadcastFactory" % bcName) \
    +                      .set("spark.broadcast.blockSize", blockSize)
    +
    +    sc = SparkContext(conf=conf)
    +    # large broadcast,using broadcast will cost less time!
    +    barr1 = sc.broadcast(range(num))
    +    for i in range(3):
    +        start = time.time()
    +        # variable barr1 cached on each machine rather than shipping a 
copy of
    +        # it with tasks threes times
    +        broadcast_result = sc.parallelize(range(10), slices)
    --- End diff --
    
    Can use move this line out of loop? then we can re-use the broadcast 
object, and see the second and third runs are faster than first one (the 
broadcast object are cached).


---
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