Giter Club home page Giter Club logo

Comments (9)

mochi-co avatar mochi-co commented on May 24, 2024

Hi @lucasjinreal - did you check https://dgraph.io/docs/badger/get-started/#memory-usage ? You should be able to apply these configurations in the Badger hook options. Maybe something like this:

// make sure to import the extra badger packages:
import badgerdb "github.com/dgraph-io/badger"
import "github.com/timshannon/badgerhold"

// some complex nesting of different structs called 'Options'
err := server.AddHook(new(badger.Hook), &badger.Options{
  Path: badgerPath,
  Options: &badgerhold.Options{
  	Options: badgerdb.Options{
  		ValueLogFileSize: 256000,
  	},
  },
})

This will give access to all the options in https://github.com/dgraph-io/badger/blob/main/options.go

Let me know if it works, if so we can update the example file.

from server.

lucasjinreal avatar lucasjinreal commented on May 24, 2024

@mochi-co thanks for reply, should I update mochi lib?

from server.

mochi-co avatar mochi-co commented on May 24, 2024

@lucasjinreal Try updating your main.go with your badger hook and see if it fixes the issue :)

from server.

lucasjinreal avatar lucasjinreal commented on May 24, 2024

I got no such field in Options.

also, why does vlog file has relation to the memory usage?

from server.

mochi-co avatar mochi-co commented on May 24, 2024

You might be missing an import - see this example:

// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: 2022 mochi-mqtt, mochi-co
// SPDX-FileContributor: mochi-co

package main

import (
	"log"
	"os"
	"os/signal"
	"syscall"

	mqtt "github.com/mochi-mqtt/server/v2"
	"github.com/mochi-mqtt/server/v2/hooks/auth"
	"github.com/mochi-mqtt/server/v2/hooks/storage/badger"
	"github.com/mochi-mqtt/server/v2/listeners"

	badgerdb "github.com/dgraph-io/badger"
	"github.com/timshannon/badgerhold"
)

func main() {
	badgerPath := ".badger"
	defer os.RemoveAll(badgerPath) // remove the example badger files at the end

	sigs := make(chan os.Signal, 1)
	done := make(chan bool, 1)
	signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
	go func() {
		<-sigs
		done <- true
	}()

	server := mqtt.New(nil)
	_ = server.AddHook(new(auth.AllowHook), nil)

	err := server.AddHook(new(badger.Hook), &badger.Options{
		Path: badgerPath,
		Options: &badgerhold.Options{
			Options: badgerdb.Options{
				ValueLogFileSize: 256000,
			},
		},
	})
	if err != nil {
		log.Fatal(err)
	}

	tcp := listeners.NewTCP("t1", ":1883", nil)
	err = server.AddListener(tcp)
	if err != nil {
		log.Fatal(err)
	}

	go func() {
		err := server.Serve()
		if err != nil {
			log.Fatal(err)
		}
	}()

	<-done
	server.Log.Warn("caught signal, stopping...")
	_ = server.Close()
	server.Log.Info("main.go finished")
}

As for vlog memory - I have no idea I'm afraid, I've never used badger in production :) Someone else here may have better ideas

from server.

werbenhu avatar werbenhu commented on May 24, 2024

@lucasjinreal Take a look at the configuration modifications and the addition of garbage collection described in #370 to see if they would be helpful for your use of BadgerDB.

from server.

lucasjinreal avatar lucasjinreal commented on May 24, 2024

@werbenhu Hi, for a user, I just want use it out-of-box.

I didn't do any further config either have a very large throughoutput on my server, the size should be small default.

But looked at the thread you linked, it's likely a existed issue and unable to fix.

So, if I want restore message simply (do't let me dive into so complicated cache machnsim)
would that only be redis?

from server.

werbenhu avatar werbenhu commented on May 24, 2024

@lucasjinreal You can now use Pebble and Badger/v4 as persistent databases. Can this issue be closed now?

from server.

lucasjinreal avatar lucasjinreal commented on May 24, 2024

Yes

from server.

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.