-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improving transit batch encrypt and decrypt latencies (#8775)
Optimized batch items decoder bypassing mapstructure
- Loading branch information
Showing
6 changed files
with
374 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package transit | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/hashicorp/vault/sdk/logical" | ||
) | ||
|
||
func BenchmarkTransit_BatchDecryption1(b *testing.B) { | ||
BTransit_BatchDecryption(b, 1) | ||
} | ||
|
||
func BenchmarkTransit_BatchDecryption10(b *testing.B) { | ||
BTransit_BatchDecryption(b, 10) | ||
} | ||
|
||
func BenchmarkTransit_BatchDecryption50(b *testing.B) { | ||
BTransit_BatchDecryption(b, 50) | ||
} | ||
|
||
func BenchmarkTransit_BatchDecryption100(b *testing.B) { | ||
BTransit_BatchDecryption(b, 100) | ||
} | ||
|
||
func BenchmarkTransit_BatchDecryption1000(b *testing.B) { | ||
BTransit_BatchDecryption(b, 1_000) | ||
} | ||
|
||
func BenchmarkTransit_BatchDecryption10000(b *testing.B) { | ||
BTransit_BatchDecryption(b, 10_000) | ||
} | ||
|
||
func BTransit_BatchDecryption(b *testing.B, bsize int) { | ||
b.StopTimer() | ||
|
||
var resp *logical.Response | ||
var err error | ||
|
||
backend, s := createBackendWithStorage(b) | ||
|
||
batchEncryptionInput := make([]interface{}, 0, bsize) | ||
for i := 0; i < bsize; i++ { | ||
batchEncryptionInput = append( | ||
batchEncryptionInput, | ||
map[string]interface{}{"plaintext": "dGhlIHF1aWNrIGJyb3duIGZveA=="}, | ||
) | ||
} | ||
|
||
batchEncryptionData := map[string]interface{}{ | ||
"batch_input": batchEncryptionInput, | ||
} | ||
|
||
batchEncryptionReq := &logical.Request{ | ||
Operation: logical.CreateOperation, | ||
Path: "encrypt/upserted_key", | ||
Storage: s, | ||
Data: batchEncryptionData, | ||
} | ||
resp, err = backend.HandleRequest(context.Background(), batchEncryptionReq) | ||
if err != nil || (resp != nil && resp.IsError()) { | ||
b.Fatalf("err:%v resp:%#v", err, resp) | ||
} | ||
|
||
batchResponseItems := resp.Data["batch_results"].([]BatchResponseItem) | ||
batchDecryptionInput := make([]interface{}, len(batchResponseItems)) | ||
for i, item := range batchResponseItems { | ||
batchDecryptionInput[i] = map[string]interface{}{"ciphertext": item.Ciphertext} | ||
} | ||
batchDecryptionData := map[string]interface{}{ | ||
"batch_input": batchDecryptionInput, | ||
} | ||
|
||
batchDecryptionReq := &logical.Request{ | ||
Operation: logical.UpdateOperation, | ||
Path: "decrypt/upserted_key", | ||
Storage: s, | ||
Data: batchDecryptionData, | ||
} | ||
|
||
b.StartTimer() | ||
for i := 0; i < b.N; i++ { | ||
resp, err = backend.HandleRequest(context.Background(), batchDecryptionReq) | ||
if err != nil || (resp != nil && resp.IsError()) { | ||
b.Fatalf("err:%v resp:%#v", err, resp) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package transit | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/hashicorp/vault/sdk/logical" | ||
) | ||
|
||
func BenchmarkTransit_BatchEncryption1(b *testing.B) { | ||
BTransit_BatchEncryption(b, 1) | ||
} | ||
|
||
func BenchmarkTransit_BatchEncryption10(b *testing.B) { | ||
BTransit_BatchEncryption(b, 10) | ||
} | ||
|
||
func BenchmarkTransit_BatchEncryption50(b *testing.B) { | ||
BTransit_BatchEncryption(b, 50) | ||
} | ||
|
||
func BenchmarkTransit_BatchEncryption100(b *testing.B) { | ||
BTransit_BatchEncryption(b, 100) | ||
} | ||
|
||
func BenchmarkTransit_BatchEncryption1000(b *testing.B) { | ||
BTransit_BatchEncryption(b, 1_000) | ||
} | ||
|
||
func BenchmarkTransit_BatchEncryption10000(b *testing.B) { | ||
BTransit_BatchEncryption(b, 10_000) | ||
} | ||
|
||
func BTransit_BatchEncryption(b *testing.B, bsize int) { | ||
b.StopTimer() | ||
|
||
var resp *logical.Response | ||
var err error | ||
|
||
backend, s := createBackendWithStorage(b) | ||
|
||
batchEncryptionInput := make([]interface{}, 0, bsize) | ||
for i := 0; i < bsize; i++ { | ||
batchEncryptionInput = append( | ||
batchEncryptionInput, | ||
map[string]interface{}{"plaintext": "dGhlIHF1aWNrIGJyb3duIGZveA=="}, | ||
) | ||
} | ||
|
||
batchEncryptionData := map[string]interface{}{ | ||
"batch_input": batchEncryptionInput, | ||
} | ||
|
||
batchEncryptionReq := &logical.Request{ | ||
Operation: logical.CreateOperation, | ||
Path: "encrypt/upserted_key", | ||
Storage: s, | ||
Data: batchEncryptionData, | ||
} | ||
|
||
b.StartTimer() | ||
for i := 0; i < b.N; i++ { | ||
resp, err = backend.HandleRequest(context.Background(), batchEncryptionReq) | ||
if err != nil || (resp != nil && resp.IsError()) { | ||
b.Fatalf("err:%v resp:%#v", err, resp) | ||
} | ||
} | ||
} |
Oops, something went wrong.