You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2018/12/04 09:45:04 UTC

[GitHub] sven-lange-last commented on issue #4155: Make ActionLimits test more reliable

sven-lange-last commented on issue #4155: Make ActionLimits test more reliable
URL: https://github.com/apache/incubator-openwhisk/pull/4155#issuecomment-444036498
 
 
   @chetanmeh thanks a lot for improving this test. I like your idea of gradually allocating memory until the limit is exceeded instead of allocating a large buffer right away. I think this change will make the action much more robust on systems that are short on virtual memory.
   
   At the same time, I'm not sure that the proposed action will always allocate enough physical memory. We are always appending the same string to the array such that memory deduplication may interfere. Can we be sure that appending the string to the array will really add a copy of the string.
   
   What do you think about following proposal:
   
   ```
   // Licensed to the Apache Software Foundation (ASF) under one or more contributor
   // license agreements; and to You under the Apache License, Version 2.0.
   
   'use strict';
   
   // Usually, Linux systems have a page size of 4096 byte
   // The actual value can be obtained with `getconf PAGESIZE`
   const pageSizeInB = 4096;
   
   // This array will be used to store all allocated pages
   // such that they won't be garbage collected
   var pages = [];
   
   // Allocates a byte array that has page size
   function allocateMemoryPage() {
       return new Uint8Array(pageSizeInB);
   }
   
   // Returns a random number between 0 (inclusive) and
   // the specified value maxExclusive (exclusive)
   function randomUnsigned(maxExclusive) {
       return Math.floor(Math.random() * maxExclusive)
   }
   
   // Fills the first 4 bytes of the passed byte array with random
   // numbers
   function fillMemoryPage(byteArray) {
       for (let i = 0; (i < 4) && (i < pageSizeInB); i++) {
           byteArray[i] = randomUnsigned(256)
       }
   }
   
   // Consumes the specified amount of physical memory
   // * The memory is allocated page-wise instead of allocating
   //   a large block of memory to prevent virtual OOM
   // * Fill randomly to prevent memory deduplication
   function eat(memoryInMiB) {
       const memoryInB = memoryInMiB * 1024 * 1024;
       const pageSizeInB = 4096;
       const memoryInPages = Math.ceil(memoryInB / pageSizeInB);
   
       for(let p = 0; p < memoryInPages; p++) {
           let byteArray = allocateMemoryPage()
           fillMemoryPage(byteArray)
           pages.push(byteArray)
       }
   }
   
   function main(msg) {
       console.log('helloEatMemory: memory ' + msg.payload + 'MB');
       global.gc();
       eat(msg.payload);
   
       console.log('helloEatMemory: completed allocating memory');
       console.log(process.memoryUsage());
   
       return {msg: 'OK, buffer of size ' + msg.payload + ' MB has been filled.'};
   }
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services