Browse code

Don't json marshal then immediately unmarshal

During container startup we end up spending a fair amount of time
encoding/decoding json.
This cuts out some of that since we already have the decoded object in
memory.

The old flow looked like:

1. Start container request
2. Create file
3. Encode container spec to json
4. Write to file
5. Close file
6. Open file
7. Read file
8. Decode container spec
9. Close file
10. Send to containerd.

The new flow cuts out steps 6-9 completely, and with it a lot of time
spent in reflect and file IO.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>

Brian Goff authored on 2017/06/22 02:42:27
Showing 2 changed files
... ...
@@ -83,8 +83,7 @@ func (clnt *client) Create(containerID string, checkpoint string, checkpointDir
83 83
 	if err := json.NewEncoder(f).Encode(spec); err != nil {
84 84
 		return err
85 85
 	}
86
-
87
-	return container.start(checkpoint, checkpointDir, attachStdio)
86
+	return container.start(&spec, checkpoint, checkpointDir, attachStdio)
88 87
 }
89 88
 
90 89
 func (clnt *client) Signal(containerID string, sig int) error {
... ...
@@ -90,12 +90,7 @@ func (ctr *container) spec() (*specs.Spec, error) {
90 90
 	return &spec, nil
91 91
 }
92 92
 
93
-func (ctr *container) start(checkpoint string, checkpointDir string, attachStdio StdioCallback) (err error) {
94
-	spec, err := ctr.spec()
95
-	if err != nil {
96
-		return nil
97
-	}
98
-
93
+func (ctr *container) start(spec *specs.Spec, checkpoint, checkpointDir string, attachStdio StdioCallback) (err error) {
99 94
 	ctx, cancel := context.WithCancel(context.Background())
100 95
 	defer cancel()
101 96
 	ready := make(chan struct{})
... ...
@@ -172,6 +167,7 @@ func (ctr *container) start(checkpoint string, checkpointDir string, attachStdio
172 172
 			State: StateStart,
173 173
 			Pid:   ctr.systemPid,
174 174
 		}})
175
+
175 176
 }
176 177
 
177 178
 func (ctr *container) newProcess(friendlyName string) *process {