Skip to content

apr_pollset_poll: The timeout specified has expired (70007) #14

Description

@ruannawe
@ruannawe ➜ /workspaces/codespaces-blank/examples/leetcode $ uname -a
Linux codespaces-e30eef 6.5.0-1025-azure #26~22.04.1-Ubuntu SMP Thu Jul 11 22:33:04 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

@ruannawe ➜ /workspaces/codespaces-blank/examples/leetcode $ go run main.go localhost:8080
Uring instance initiated!
Uring instance initiated!
Uring instance initiated!
Add Kernel buffer... for ring  0
Add Kernel buffer... for ring  1
Add Kernel buffer... for ring  2
@ruannawe ➜ /workspaces/codespaces-blank $ ab -n 300000 -c 1000 http://localhost:8080/
This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
apr_pollset_poll: The timeout specified has expired (70007)
package main

import (
	"bytes"
	"os"
	"sync"
	"time"

	uringnet "github.com/y001j/uringnet"
	socket "github.com/y001j/uringnet/sockets"
)

type testServer struct {
	uringnet.BuiltinEventEngine

	testloop *uringnet.Ringloop
	//ring      *uring_net.URingNet
	addr      string
	multicore bool
}

type httpCodec struct {
	delimiter []byte
	buf       []byte
}

func appendResponse(hc *[]byte) {
	*hc = append(*hc, "HTTP/1.1 200 OK\r\nServer: uringNet\r\nContent-Type: text/plain\r\nDate: "...)
	*hc = time.Now().AppendFormat(*hc, "Mon, 02 Jan 2006 15:04:05 GMT")
	*hc = append(*hc, "\r\nContent-Length: 12\r\n\r\nHello World!"...)
}

var (
	errMsg      = "Internal Server Error"
	errMsgBytes = []byte(errMsg)
)

func (ts *testServer) OnTraffic(data *uringnet.UserData, ringnet *uringnet.URingNet) uringnet.Action {

	//将data.Buffer转换为string
	//buffer := data.Buffer[:data.BufSize]

	buffer := ringnet.ReadBuffer
	//tes :=
	//fmt.Println("data:", " offset: ", tes, " ", data.BufOffset)
	//获取tes中“\r\n\r\n”的数量
	count := bytes.Count(buffer, []byte("GET"))
	if count == 0 {
		//appendResponse(&data.WriteBuf)
		//return UringNet.Close
		return uringnet.None
	} else {
		for i := 0; i < count; i++ {
			appendResponse(&data.WriteBuf)
		}
	}
	return uringnet.Echo
}

func (ts *testServer) OnWritten(data uringnet.UserData) uringnet.Action {

	return uringnet.None
}

func (ts *testServer) OnOpen(data *uringnet.UserData) ([]byte, uringnet.Action) {

	ts.SetContext(&httpCodec{delimiter: []byte("\r\n\r\n")})
	return nil, uringnet.None
}

func main() {
	addr := os.Args[1]
	//runtime.GOMAXPROCS(runtime.NumCPU()*2 - 1)

	options := socket.SocketOptions{TCPNoDelay: socket.TCPNoDelay, ReusePort: true}
	ringNets, _ := uringnet.NewMany(uringnet.NetAddress{socket.Tcp4, addr}, 3200, true, 3, options, &testServer{}) //runtime.NumCPU()

	loop := uringnet.SetLoops(ringNets, 4000)

	var waitgroup sync.WaitGroup
	waitgroup.Add(1)

	loop.RunMany()

	waitgroup.Wait()
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions