Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mitogen
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
mitogen
Commits
0f82f68f
Commit
0f82f68f
authored
Mar 06, 2018
by
Alex Willmer
Committed by
David Wilson
Mar 19, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
parent: Precompute preamble sizes for first stage
SSH command size: 453 (no change) Preamble size: 8941 (-5 bytes)
parent
dfd7070c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
8 deletions
+13
-8
mitogen/parent.py
mitogen/parent.py
+12
-7
tests/first_stage_test.py
tests/first_stage_test.py
+1
-1
No files found.
mitogen/parent.py
View file @
0f82f68f
...
...
@@ -318,9 +318,12 @@ class Stream(mitogen.core.Stream):
)
)
# base64'd and passed to 'python -c'. It forks, dups 0->100, creates a
# pipe, then execs a new interpreter with a custom argv. 'CONTEXT_NAME' is
# replaced with the context name. Optimized for size.
# Minimised, gzipped, base64'd and passed to 'python -c'. It forks, dups
# file descriptor 0 as 100, creates a pipe, then execs a new interpreter
# with a custom argv.
# 'CONTEXT_NAME', 'PREAMBLE_COMPRESSED_LEN', and 'PREAMBLE_LEN' are
# substituted with their respective values.
# Optimized for minimum byte count after minification & compression.
@
staticmethod
def
_first_stage
():
import
os
,
sys
...
...
@@ -337,9 +340,9 @@ class Stream(mitogen.core.Stream):
os
.
environ
[
'ARGV0'
]
=
e
=
sys
.
executable
os
.
execv
(
e
,[
'mitogen:CONTEXT_NAME'
])
os
.
write
(
1
,
'EC0
\
n
'
)
C
=
_
(
sys
.
stdin
.
read
(
input
()
),
'zlib'
)
C
=
_
(
sys
.
stdin
.
read
(
PREAMBLE_COMPRESSED_LEN
),
'zlib'
)
os
.
fdopen
(
W
,
'w'
,
0
).
write
(
C
)
os
.
fdopen
(
w
,
'w'
,
0
).
write
(
'
%s
\
n
'
%
len
(
C
)
+
C
)
os
.
fdopen
(
w
,
'w'
,
0
).
write
(
'
PREAMBLE_LEN
\
n
'
+
C
)
os
.
write
(
1
,
'EC1
\
n
'
)
def
get_boot_command
(
self
):
...
...
@@ -347,6 +350,9 @@ class Stream(mitogen.core.Stream):
source
=
textwrap
.
dedent
(
'
\
n
'
.
join
(
source
.
strip
().
split
(
'
\
n
'
)[
2
:]))
source
=
source
.
replace
(
' '
,
'
\
t
'
)
source
=
source
.
replace
(
'CONTEXT_NAME'
,
self
.
remote_name
)
preamble_compressed
=
self
.
get_preamble
()
source
=
source
.
replace
(
'PREAMBLE_COMPRESSED_LEN'
,
str
(
len
(
preamble_compressed
)))
source
=
source
.
replace
(
'PREAMBLE_LEN'
,
str
(
len
(
zlib
.
decompress
(
preamble_compressed
))))
encoded
=
zlib
.
compress
(
source
,
9
).
encode
(
'base64'
).
replace
(
'
\
n
'
,
''
)
# We can't use bytes.decode() in 3.x since it was restricted to always
# return unicode, so codecs.decode() is used instead. In 3.x
...
...
@@ -374,8 +380,7 @@ class Stream(mitogen.core.Stream):
'blacklist'
:
self
.
_router
.
get_module_blacklist
(),
},)
compressed
=
zlib
.
compress
(
minimize_source
(
source
),
9
)
return
str
(
len
(
compressed
))
+
'
\
n
'
+
compressed
return
zlib
.
compress
(
minimize_source
(
source
),
9
)
create_child
=
staticmethod
(
create_child
)
...
...
tests/first_stage_test.py
View file @
0f82f68f
...
...
@@ -36,7 +36,7 @@ class CommandLineTest(testlib.RouterMixin, testlib.TestCase):
stdout
,
stderr
=
proc
.
communicate
()
self
.
assertEquals
(
0
,
proc
.
returncode
)
self
.
assertEquals
(
"EC0
\
n
"
,
stdout
)
self
.
assertIn
(
"E
OFError
"
,
stderr
)
self
.
assertIn
(
"E
rror -5 while decompressing data: incomplete or truncated stream
"
,
stderr
)
if
__name__
==
'__main__'
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment