Skip to content

Commit

Permalink
memory optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
uoosef committed Nov 23, 2023
1 parent d7b905e commit ba04ea0
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,14 @@ type readOnlyConn struct {
reader io.Reader
}

func (conn readOnlyConn) Read(p []byte) (int, error) { return conn.reader.Read(p) }
func (conn readOnlyConn) Write(p []byte) (int, error) { return 0, io.ErrClosedPipe }
func (conn readOnlyConn) Close() error { return conn.Close() }
func (conn readOnlyConn) Read(p []byte) (int, error) { return conn.reader.Read(p) }
func (conn readOnlyConn) Write(p []byte) (int, error) { return 0, io.ErrClosedPipe }
func (conn readOnlyConn) Close() error {
if tcpConn, ok := conn.reader.(io.Closer); ok {
return tcpConn.Close()
}
return nil
}
func (conn readOnlyConn) LocalAddr() net.Addr { return nil }
func (conn readOnlyConn) RemoteAddr() net.Addr { return nil }
func (conn readOnlyConn) SetDeadline(t time.Time) error { return nil }
Expand Down Expand Up @@ -311,6 +316,11 @@ func runDOHServer(limiter *rate.Limiter) {
}

func main() {
err := os.Setenv("GOGC", "50")
if err != nil {
log.Fatal(err)
} // Set GOGC to 50 to make GC more aggressive

cfg, err := LoadConfig("config.json")
if err != nil {
log.Fatalf("Failed to load configuration: %v", err)
Expand Down

0 comments on commit ba04ea0

Please sign in to comment.