[ 
https://issues.apache.org/jira/browse/BEAM-9085?focusedWorklogId=419086&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-419086
 ]

ASF GitHub Bot logged work on BEAM-9085:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 09/Apr/20 02:33
            Start Date: 09/Apr/20 02:33
    Worklog Time Spent: 10m 
      Work Description: tvalentyn commented on pull request #11092: [BEAM-9085] 
Fix performance regression in SyntheticSource
URL: https://github.com/apache/beam/pull/11092#discussion_r405921080
 
 

 ##########
 File path: sdks/python/apache_beam/testing/synthetic_pipeline.py
 ##########
 @@ -61,6 +65,35 @@
   np = None
 
 
+class _Random(Random):
+  """A subclass of `random.Random` from the Python Standard Library that
+  provides a method returning random bytes of arbitrary length.
+  """
+
+  # `numpy.random.RandomState` does not provide `random()` method, we keep this
+  # for compatibility reasons.
+  random_sample = Random.random
+
+  def bytes(self, length):
+    """Returns random bytes.
+
+    Args:
+      length (int): Number of random bytes.
+    """
+    n = length // 8 + 1
+    # pylint: disable=map-builtin-not-iterating
+    return struct.pack(
+        '{}Q'.format(n),
+        *map(self.getrandbits, itertools.repeat(64, n)))[:length]
 
 Review comment:
   Since we don't need py2 compatibility anymore, consider using `to_bytes`. 
Here's an equivalent for chunk_size=8. It seems to be somewhat slower than 
current method (perhaps since I'm not using `map+repeat()`), but with larger 
`chuck_size`, seems to be more efficient. Large chunk size may be less 
efficient for short bytesequences.
   
   ```
   chunk_size_bytes = 8 // TBD - larger chunks seem to improve performance.
   chunk_size_bits = chunk_size_bytes * 8
   num_chunks = length // chunk_size_bytes + 1
   
   return 
b''.join([self.getrandbits(chunk_size_bits).to_bytes(chunk_size_bytes, 
sys.byteorder) for _ in range(num_chunks)])[:length]
   ```
   
   If you decide to keep current implementation - please add a comment 
explaining the mechanics for readers not familiar with this code (we generate 
8-byte stings, and then fit them into a representation of C++'s long-long, 
which also takes up 8 bytes).
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 419086)
    Time Spent: 8h  (was: 7h 50m)

> Performance regression in np.random.RandomState() skews performance test 
> results across Python 2/3 on Dataflow
> --------------------------------------------------------------------------------------------------------------
>
>                 Key: BEAM-9085
>                 URL: https://issues.apache.org/jira/browse/BEAM-9085
>             Project: Beam
>          Issue Type: Bug
>          Components: testing
>            Reporter: Kamil Wasilewski
>            Assignee: Kamil Wasilewski
>            Priority: Major
>          Time Spent: 8h
>  Remaining Estimate: 0h
>
> Tests show that the performance of core Beam operations in Python 3.x on 
> Dataflow can be a few time slower than in Python 2.7. We should investigate 
> what's the cause of the problem.
> Currently, we have one ParDo test that is run both in Py3 and Py2 [1]. A 
> dashboard with runtime results can be found here [2].
> [1] sdks/python/apache_beam/testing/load_tests/pardo_test.py
> [2] https://apache-beam-testing.appspot.com/explore?dashboard=5678187241537536



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to