Commit Graph

208 Commits (de12097bc475b1d118c7d70c516c95083af5017c)

Author SHA1 Message Date
David Wilson bd4d55dc90 issue #550: parent: add explanatory comment. 5 years ago
David Wilson 87c8ab4323 issue #550: fix up TTY ioctls on WSL 2016 Anniversary Update 5 years ago
David Wilson c1d73e1f4f issue #535: parent: add create_socketpair(size=..) parameter. 5 years ago
David Wilson 9bcd2ec56c issue #542: return of select poller, new selection logic 5 years ago
David Wilson 1f77d24bec Update copyright year everywhere. 5 years ago
David Wilson 7ff4e6694c issue #536: rework how 2.3-compatible simplejson is served
Regardless of the version of simplejson loaded in the master, load up
the ModuleResponder cache with our 2.4-compatible version.

To cope with simplejson being loaded due to modules like ec2_group that
try to import it before importing 'json', also update target.py to
remove it from the whitelist if a local 'json' module import succeeds.
5 years ago
David Wilson 0e193c223c issue #508: master: minify all Mitogen/ansible_mitogen sources.
Minify-safe files are marked with a magical "# !mitogen: minify_safe"
comment anywhere in the file, which activates the minifier. The result
is naturally cached by ModuleResponder, therefore lru_cache is gone too.

Given:

    import os, mitogen
    @mitogen.main()
    def main(router):
        c = router.ssh(hostname='k3')
        c.call(os.getpid)
        router.sudo(via=c)

SSH footprint drops from 56.2 KiB to 42.75 KiB (-23.9%)
Ansible "shell: hostname" drops 149.26 KiB to 117.42 KiB (-21.3%)
5 years ago
David Wilson cfb94e463f parent: PartialZlib docstrings. 5 years ago
David Wilson 9adc38d8ec parent: pre-cache bootstrap if possible.
When the interpreter is modern enough, use zlib.compressobj() to
pre-compress the unchanging parts of the bootstrap once, then use
compressobj.copy() to append just the context's config during stream
construction.

Before: 100 loops, best of 3: 5.81 msec per loop
After: 10000 loops, best of 3: 35.9 usec per loop

With 100 targets this is enough to knock 6 seconds off startup, at 500
targets it becomes half a minute.

Test 'program':
        python -m timeit -s '
                import mitogen.parent as p;
                import mitogen.master as m;
                r=m.Router();
                s=p.Stream(r, 0, max_message_size=1);
                r.broker.shutdown()'\
                \
                's.get_preamble()'
5 years ago
David Wilson 7ca927608c parent: synchronize get_core_source()
Single task 100 SSH target run, before:

        3533181 function calls (3533083 primitive calls) in 616.688 seconds
        User time (seconds): 32.52
        System time (seconds): 2.71
        Percent of CPU this job got: 64%
        Elapsed (wall clock) time (h:mm:ss or m:ss): 0:54.88

After:

        451602 function calls (451504 primitive calls) in 570.746 seconds
        User time (seconds): 29.48
        System time (seconds): 2.81
        Percent of CPU this job got: 67%
        Elapsed (wall clock) time (h:mm:ss or m:ss): 0:48.20
5 years ago
David Wilson e77048ec2d utils: pad out reset_affinity() and integrate with detach_popen() 5 years ago
David Wilson 568044438d parent: don't kill children when profiling is active. 5 years ago
David Wilson 407294cd79 issue #498: prevent crash on double 'disconnect' signal.
Fixes:

ERROR! [pid 1096] 23:31:48.363215 E mitogen: _broker_main() crashed
Traceback (most recent call last):
  File "/home/dmw/src/mitogen/mitogen/core.py", line 2917, in _broker_main
    self._loop_once()
  File "/home/dmw/src/mitogen/mitogen/core.py", line 2875, in _loop_once
    self._call(side.stream, func)
  File "/home/dmw/src/mitogen/mitogen/core.py", line 2860, in _call
    stream.on_disconnect(self)
  File "/home/dmw/src/mitogen/mitogen/parent.py", line 1161, in on_disconnect
    super(Stream, self).on_disconnect(broker)
  File "/home/dmw/src/mitogen/mitogen/core.py", line 1534, in on_disconnect
    fire(self, 'disconnect')
  File "/home/dmw/src/mitogen/mitogen/core.py", line 390, in fire
    func(*args, **kwargs)
  File "/home/dmw/src/mitogen/mitogen/parent.py", line 1794, in <lambda>
    func=lambda: self._on_stream_disconnect(stream),
  File "/home/dmw/src/mitogen/mitogen/parent.py", line 1810, in _on_stream_disconnect
    routes = self._routes_by_stream.pop(stream)
KeyError: mitogen.ssh.Stream('ssh.localhost:2236')
5 years ago
David Wilson 9aa845669c issue #413: don't double-propagate DEL_ROUTE to parent.
propagate_up() sends ADD_ROUTE and DEL_ROUTE

propagate_down() sends only DEL_ROUTE, but didn't bother checking if
up() had sent it already.

Fixes:

     ERROR! [pid 41060] 17:55:30.739159 E mitogen.ctx.ssh.localhost:
     mitogen: RouteMonitor(): received DEL_ROUTE for 6081 from
     mitogen.fork.Stream(u'fork.41142'), expected
     mitogen.core.Stream('parent')
5 years ago
David Wilson e2478dcb9f issue #498: wrap Router dict mutations in a lock 5 years ago
David Wilson ec789513dc ssh: tidy up logs and stream names. 5 years ago
David Wilson 4095358ea4 Merge commit '5bd6bd0' into envtest
* commit '5bd6bd0':
  parent: don't send messages on streams that no longer exist; closes #480
5 years ago
David Wilson d0075e7e50 parent: --with-pydebug bootstrap could fail due to corrupted stream
Due to first stage writin 'XXX refs' on exit. So close stderr as last
step of first stage.
5 years ago
David Wilson 2e4d7b15d7 parent: don't kill child when profiling=True 5 years ago
David Wilson 61297c24e5 issue #477: call_function_test fixes for 2.4. 5 years ago
David Wilson f1a712fad3 issue #477: Python<2.5 ioctl() request parameter was signed. 5 years ago
David Wilson 5bd6bd06d1 parent: don't send messages on streams that no longer exist; closes #480 5 years ago
David Wilson ffd46e9f1c issue #477: parent: make iter_read() log disconnect reason. 5 years ago
David Wilson 87d2af4c6e issue #477: polyfill partition() use in mitogen.parent. 5 years ago
David Wilson 07f1b9bdd0 issue #477: Python 2.5 needs next() polyfill too. 6 years ago
David Wilson 0ee8ee78b8 issue #477: Py2.4 cannot tolerate unicode kwargs. 6 years ago
David Wilson f3dae10fe1 issue #477: 2.4/2.5 had no better poller than poll(). 6 years ago
David Wilson 881dc7d5ca issue #477: more 2.4-compatible thread.get_ident() use. 6 years ago
David Wilson fb750edfa7 issue #61: fix bare except (reported by LGTM) 6 years ago
David Wilson 767737265a issue #61: add inverse comparison (reported by LGTM) 6 years ago
David Wilson 51bd35280a issue #61: remove duplicated method (reported by LGTM) 6 years ago
David Wilson ea9ef50b3c issue #415: replace default Poller with select.poll()
30% latency reduction for IPC.
6 years ago
David Wilson fd90834944 issue #408: fix test fallout. 6 years ago
David Wilson 51ac309647 issue #408: 2.4 compat: replace iter_read with explicit generator
Can't use yield inside try/finally on 2.4.
6 years ago
David Wilson 57b652eddc parent: remove unused imports
The stray functools import must have been there forever! Instant 4kb
knocked off wire footprint.
6 years ago
David Wilson de719fa249 core: throw error on duplicate add_handler(); closes #447. 6 years ago
David Wilson 85e965118d Merge remote-tracking branch 'origin/issue462'
* origin/issue462:
  issue #462: docs: update Changelog.
  parent: cope with broken /dev/pts on Linux; closes #462.
6 years ago
David Wilson 8fa3c74de4 issue #426: RouterMonitor format incorrect for 3->2 forward.
Each hop would cause "b''" to be wrapped around the context name.
6 years ago
David Wilson a4c7a98dd9 parent: cope with broken /dev/pts on Linux; closes #462. 6 years ago
David Wilson 2f3a8f2a32 parent: proxy_connect docstring. 6 years ago
David Wilson 3f5774cfd5 core: document/tidy up poller.
Remove duplicate attribute creates in subclasses too.
6 years ago
David Wilson 3876590aa1 parent: add descriptive errors for unsupported call() types.
Closes #439.
6 years ago
David Wilson 045db6f689 Fix iter_read() FD leaks on 3.x; closes #418. 6 years ago
David Wilson 76ec4f201c issue #413: paper over harmless duplicate del_route()
Ideally it would only be called once, and in future maybe it can, but
right now we need to cope with these cases:

* Downstream parent notifies us of disconnection (DEL_ROUTE)
* We notify ourself of disconnection
* We notify ourself and so does downstream parent

It's case 3 that causes the error.
6 years ago
David Wilson 802de6a8d5 issue #406: clean up DiagLogStream handling and connect() failure.
When Stream.connect() fails, have it just use on_disconnect(). Now there
is a single disconnect cleanup path.

Remove cutpasted DiagLogStream setup/destruction, and move it into the
base class (temporarily), and only manage the lifetime of its underlying
FD via Side.close().  This cures another EBADF failure.
6 years ago
David Wilson dc3db49c5a issue #406: more leaked FDs when create_child() fails. 6 years ago
David Wilson 17631b0573 issue #406: parent: close extra_fd on failure too. 6 years ago
David Wilson b3841317dd issue #406: clean up FDs on failure explicitly
The previous approach was crap since it left e.g. socketpair instances
lying around for GC with their underlying FD already closed, coupled
with FD number reuse, led to random madness when GC finally runs.
6 years ago
David Wilson 375182b71b issue #406: don't leak side FDs on bootstrap failure. 6 years ago
David Wilson 14b389cb46 issue #406: don't leak FDs on failed child start. 6 years ago