Skip to main content

a deque like implementation using multiprocessing.shared_memory

Project description

shared-memory-deque

readme

StaticQueue class memes the collections.deque interface. The goal for this class was to improve performance of mp.Queue class.

Outcome: shared-memory-deque is slower than the classic mp.Queue. The supplied implementation is limited to static size per item and bytes only. Pickling is not included and needs to be done in front. So I dropped the idea and did not finalize. One clear advantage is the pickle-ability of shared-memory-deque. So it can be easily invoked anywhere without the need to inherit from the process spwan/fork.

install

pip install shared-memory-deque

usage

from shared_memory_deque import StaticDeque
deque = StaticDeque(10, 2)
deque.append(b"ed")
deque.pop()

bottle neck

I found that the memoryview assignment of large chunk size is the most time-consuming. A possible workaround could to have a second data object which is build counter-wise. so that one could do a pop_left as a pop from a reversed(data) Another solution could be to just ignore the leading bytes until the memory chunk is consumed with data. When put then a new block is created and assigned. One could use a first pointer.

Function: pop_left at line 72

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
    72                                               def pop_left(self):
    73     10000     441134.0     44.1      6.3          if not self.is_empty:
    74     10000     228660.0     22.9      3.3              res = self.data.buf[:self.length].tobytes()
    75     10000    5496619.0    549.7     78.8              self.data.buf[:self._memsize - self.length] = self.data.buf[self.length:self._memsize]
    76     10000     754754.0     75.5     10.8              self.last = self.last - self.length
    77     10000      53957.0      5.4      0.8              return res
    78                                                   else:
    79                                                       raise Empty

future

Not sure if I will add more free time to this little project. So don't use this module for production or anything else half ways serious.

Copyright © 2022 Simon Bauer

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

shared-memory-deque-0.1.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

shared_memory_deque-0.1-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file shared-memory-deque-0.1.tar.gz.

File metadata

  • Download URL: shared-memory-deque-0.1.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.0

File hashes

Hashes for shared-memory-deque-0.1.tar.gz
Algorithm Hash digest
SHA256 4fd61f9f0c1eb4dcffc0584645432ec1b888da1fa26828f41cea9c702fb9c45a
MD5 54fd3b7e738249544073514b7285338a
BLAKE2b-256 51928eb4d7e7a86fbe4ae7d82dc71dfbacda300afe6cb78c8ef67251b38d9422

See more details on using hashes here.

File details

Details for the file shared_memory_deque-0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for shared_memory_deque-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a889a974f3da6401842987965b75fdaf7ad93d8efff8745399e966a1f6a31b7f
MD5 2c7a49d51345fe2e0552997cd9d5a3ab
BLAKE2b-256 5f2d58e215352766647c5fad6abb5b42df6c20b7e06f8433814babab89985ca6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page