Skip to content

Commit

Permalink
Benchmarking, packaging, and fix issues, tests and perfomance (#797)
Browse files Browse the repository at this point in the history
### performance
- handling of the very big packet(any size that can be buffered)
- speeding up TCP sessions by using message hints: Added **proto.HasFullPayload** that helps to validate the entire HTTP request, it supports `Chunked` encoding too! Added **proto.HasRequestTitle** and **proto.HasResponseTitle** for validating the beginning of HTTP request. Those methods are used `input_raw.go` with `TCP`.
- supports Keep-Alive: the above functions helps to support keep-alive

### Packaging
- **capture:** engines(capture/doc.go)
- **tcp:** tcp message parser (tcp/doc.go)

### benchmarking
- **capture.BenchmarkPcapDump:** the benchmarks regarding dumping packets in a pcap file
- **capture.BenchmarkPcapFile:** the benchmarks of reading packets from a pcap file
- **capture.BenchmarkPcap:** the benchmarks of parsing packets from the loopback interface with pcap handles
- **proto.BenchmarkHasFullPayload:**: benchmarking this function which validates the HTTP payload
- **tcp.BenchmarkPacketParseAndSort:** benchmarks of parsing and sorting packets
- **tcp.BenchmarkMessageParserWithoutHint:** benchmarks of message reasembling by using `SYN` and `FIN` flag
- **tcp.BenchmarkMessageParserWithHint:** benchmarks of message reasembling by using `proto.HasRequestTitle` and `proto.HasFullPayload` flag

### issues
see linked issues

###  tests
- fixed input raw and engine tests

**Most of the changed of the files, was about using functionalities of** `tcp` **and** `capture` **in existing functionalities**
  • Loading branch information
Urban Ishimwe authored Aug 11, 2020
1 parent 2f81fba commit fdc8b09
Show file tree
Hide file tree
Showing 60 changed files with 3,146 additions and 3,865 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: go
go: 1.14
script: sudo -E bash -c "source /etc/profile && eval '$(gimme 1.14)' && export GOPATH=$HOME/gopath:$GOPATH && go get && GORACE='halt_on_error=1' go test ./... -v -timeout 120s -race"
script: sudo -E bash -c "source /etc/profile && eval '$(gimme 1.14)' && export GOPATH=$HOME/gopath:$GOPATH && go test ./... -v -timeout 120s"

before_install:
- sudo apt-get install libpcap-dev -y
15 changes: 14 additions & 1 deletion byteutils/byteutils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
// Package byteutils probvides helpers for working with byte slices
// Package byteutils provides helpers for working with byte slices
package byteutils

import (
"reflect"
"unsafe"
)

// Cut elements from slice for a given range
func Cut(a []byte, from, to int) []byte {
copy(a[from:], a[to:])
Expand Down Expand Up @@ -41,3 +46,11 @@ func Replace(a []byte, from, to int, new []byte) []byte {
copy(a[from:], new)
return a
}

// SliceToString preferred for large body payload (zero allocation and faster)
func SliceToString(buf *[]byte, s *string) {
bHeader := (*reflect.SliceHeader)(unsafe.Pointer(buf))
sHeader := (*reflect.StringHeader)(unsafe.Pointer(s))
sHeader.Data = bHeader.Data
sHeader.Len = bHeader.Len
}
8 changes: 8 additions & 0 deletions byteutils/byteutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,11 @@ func TestReplace(t *testing.T) {
t.Error("Should replace when replacement length bigger")
}
}

func BenchmarkStringtoSlice(b *testing.B) {
b.StopTimer()
buf := make([]byte, b.N)
b.StartTimer()
s := new(string)
SliceToString(&buf, s)
}
Loading

0 comments on commit fdc8b09

Please sign in to comment.