Giter Site home page Giter Site logo

I implemented a hot restart on fasthttp, but it cannot be implemented on atreugo because I can't access net.listen of atreugo.server about atreugo HOT 9 CLOSED

savsgio avatar savsgio commented on May 17, 2024
I implemented a hot restart on fasthttp, but it cannot be implemented on atreugo because I can't access net.listen of atreugo.server

from atreugo.

Comments (9)

savsgio avatar savsgio commented on May 17, 2024 1

Can I use server.ServerPtr() or server.RouterPtr() ?
Because in a project I might want to set router.RedirectTrailingSlash to false.
Thanks. :-)

Finally, I added this https://godoc.org/github.com/savsgio/atreugo#Atreugo.RedirectTrailingSlash.
Now you could change internal options of router.

I will release a new version in a few days.

PD: I don't add ServerPtr and RouterPtr, to protect it of bad uses that could break atreugo

from atreugo.

imxxiv avatar imxxiv commented on May 17, 2024 1

I know, Thanks for add RedirectTrailingSlash.

from atreugo.

imxxiv avatar imxxiv commented on May 17, 2024

Can I use server.ServerPtr() or server.RouterPtr() ?
Because in a project I might want to set router.RedirectTrailingSlash to false.
Thanks. :-)

from atreugo.

savsgio avatar savsgio commented on May 17, 2024

What do you mean with I can't access net.listen of atreugo.server??

from atreugo.

imxxiv avatar imxxiv commented on May 17, 2024
func createListener(addr string) (net.Listener, error) {
	//ln, err := net.Listen("tcp", addr)
	ln, err := reuseport.Listen("tcp6", addr)
	if err != nil {
		return nil, err
	}

	return ln, nil
}
func createOrImportListener(addr string) (net.Listener, error) {
	// Try and import a listener for addr. If it's found, use it.
	ln, err := importListener(addr)
	if err == nil {
		fmt.Printf("Imported listener file descriptor for %v.\n", addr)
		return ln, nil
	}

	// No listener was imported, that means this process has to create one.
	ln, err = createListener(addr)
	if err != nil {
		return nil, err
	}

	fmt.Printf("Created listener file descriptor for %v.\n", addr)
	return ln, nil
}

In order to achieve hot restart, I have to get ln, but getListener() in atreugo is private function

from atreugo.

savsgio avatar savsgio commented on May 17, 2024

You don't need access to getListener(), because you could create your own listener and use it with myatreugoserver.Serve(ln).
getListener it's just for ListenAndServe()

If you need a listener with reuseport, you could set to true the Reuseport option in configuration, and run server with ListenAndServe(), avoiding to create a FileListener shared with child processes, because you could run any servers that using the same port (with different listeners) at the same time.

The both options are valid.

from atreugo.

savsgio avatar savsgio commented on May 17, 2024

So, if you want to create your own listener, change this function with something like that:

func startServer(ln net.Listener) *atreugo.Atreugo {
	config := &atreugo.Config{
		Name: "fast",
	}
	server := atreugo.New(config)

	server.Path("GET", "/hello", handler)
	//r.GET("/test", test)
	//r.GET("/web", web)

	go server.Serve(ln)

	return server
}

from atreugo.

imxxiv avatar imxxiv commented on May 17, 2024

Reuseport can listen same port at the same time !

Then in principle, it is very simple to implement hot restart.

  1. set reuseport true and ServeGracefully true, compile and run the program
  2. after add handle, compile and run the program angin, and kill the old pid of the old program

The old server will Gracefully exit, and new server will go on to work.
Is this correct in my understanding?

from atreugo.

savsgio avatar savsgio commented on May 17, 2024

Yep 😄 hehe

from atreugo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.