cache read performance improvements

This commit is contained in:
ston1th 2022-05-19 01:29:23 +02:00
commit f69d3149f3
14 changed files with 140 additions and 71 deletions

View file

@ -101,19 +101,27 @@ func (fs *FS) connect(ctx context.Context) {
go fs.keepAlive(ctx)
fs.keepalive = true
}
fs.client, err = sftp.NewClient(fs.c,
client, err := sftp.NewClient(fs.c,
sftp.UseFstat(true),
sftp.UseConcurrentReads(true),
sftp.UseConcurrentWrites(true),
//sftp.MaxPacketChecked(32768*2),
//sftp.MaxPacketUnchecked(32768*2),
//sftp.MaxConcurrentRequestsPerFile(128),
)
select {
case <-ctx.Done():
return
case e := <-fs.wait(ctx):
log.V(2).Info("connection lost", "err", e)
fs.conn.Close()
fs.client = connError{}
fs.c = nil
if err == nil {
fs.client = client
select {
case <-ctx.Done():
return
case e := <-fs.wait(ctx):
log.V(2).Info("connection lost", "err", e)
fs.conn.Close()
fs.client = connError{}
fs.c = nil
}
} else {
log.Error(err, "error creating client")
}
} else {
log.Error(err, "error connecting")
@ -197,31 +205,6 @@ func (fs *FS) path(p string) string {
return filepath.Join(fs.root, filepath.FromSlash(path.Clean("/"+p)))
}
type file struct {
*sftp.File
fs *FS
}
func (f *file) ReadDir(_ int) (d []fs.DirEntry, err error) {
list, err := f.Readdir(0)
if err != nil {
return
}
d = make([]fs.DirEntry, len(list))
for i, v := range list {
d[i] = fs.FileInfoToDirEntry(v)
}
return
}
func (f *file) Readdir(_ int) ([]fs.FileInfo, error) {
return f.fs.client.ReadDir(f.Name())
}
func (file) Fd() uintptr {
return 0
}
func sshConfig(u *url.URL) (c *ssh.ClientConfig, err error) {
if u.User == nil {
return nil, errors.New("missing username")
@ -233,8 +216,9 @@ func sshConfig(u *url.URL) (c *ssh.ClientConfig, err error) {
c = &ssh.ClientConfig{
Config: ssh.Config{
//KeyExchanges: []string{"curve25519-sha256"},
Ciphers: []string{"aes128-ctr"},
MACs: []string{"hmac-sha2-256"},
//Ciphers: []string{"aes128-ctr"},
Ciphers: []string{"chacha20-poly1305@openssh.com"},
//MACs: []string{"hmac-sha2-256"},
},
User: u.User.Username(),
Timeout: time.Second * 30,