当前位置: 首页>>代码示例>>Golang>>正文


Golang Config.DataFileSize方法代码示例

本文整理汇总了Golang中github.com/valyala/ybc/bindings/go/ybc.Config.DataFileSize方法的典型用法代码示例。如果您正苦于以下问题:Golang Config.DataFileSize方法的具体用法?Golang Config.DataFileSize怎么用?Golang Config.DataFileSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/valyala/ybc/bindings/go/ybc.Config的用法示例。


在下文中一共展示了Config.DataFileSize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: createCache

func createCache() ybc.Cacher {
	config := ybc.Config{
		MaxItemsCount: ybc.SizeT(*maxItemsCount),
		DataFileSize:  ybc.SizeT(*cacheSize) * ybc.SizeT(1024*1024),
	}

	var err error
	var cache ybc.Cacher

	cacheFilesPath_ := strings.Split(*cacheFilesPath, ",")
	cacheFilesCount := len(cacheFilesPath_)
	logMessage("Opening data files. This can take a while for the first time if files are big")
	if cacheFilesCount < 2 {
		if cacheFilesPath_[0] != "" {
			config.DataFile = cacheFilesPath_[0] + ".cdn-booster.data"
			config.IndexFile = cacheFilesPath_[0] + ".cdn-booster.index"
		}
		cache, err = config.OpenCache(true)
		if err != nil {
			logFatal("Cannot open cache: [%s]", err)
		}
	} else if cacheFilesCount > 1 {
		config.MaxItemsCount /= ybc.SizeT(cacheFilesCount)
		config.DataFileSize /= ybc.SizeT(cacheFilesCount)
		var configs ybc.ClusterConfig
		configs = make([]*ybc.Config, cacheFilesCount)
		for i := 0; i < cacheFilesCount; i++ {
			cfg := config
			cfg.DataFile = cacheFilesPath_[i] + ".cdn-booster.data"
			cfg.IndexFile = cacheFilesPath_[i] + ".cdn-booster.index"
			configs[i] = &cfg
		}
		cache, err = configs.OpenCluster(true)
		if err != nil {
			logFatal("Cannot open cache cluster: [%s]", err)
		}
	}
	logMessage("Data files have been opened")
	return cache
}
开发者ID:valyala,项目名称:ybc,代码行数:40,代码来源:main.go

示例2: main

func main() {
	iniflags.Parse()

	runtime.GOMAXPROCS(*goMaxProcs)

	syncInterval_ := *syncInterval
	if syncInterval_ <= 0 {
		syncInterval_ = ybc.ConfigDisableSync
	}
	config := ybc.Config{
		MaxItemsCount:   ybc.SizeT(*maxItemsCount),
		DataFileSize:    ybc.SizeT(*cacheSize) * ybc.SizeT(1024*1024),
		HotItemsCount:   ybc.SizeT(*hotItemsCount),
		HotDataSize:     ybc.SizeT(*hotDataSize),
		DeHashtableSize: *deHashtableSize,
		SyncInterval:    syncInterval_,
	}

	var cache ybc.Cacher
	var err error

	cacheFilesPath_ := strings.Split(*cacheFilesPath, ",")
	cacheFilesCount := len(cacheFilesPath_)
	log.Printf("Opening data files. This can take a while for the first time if files are big\n")
	if cacheFilesCount < 2 {
		if cacheFilesPath_[0] != "" {
			config.DataFile = cacheFilesPath_[0] + ".go-memcached.data"
			config.IndexFile = cacheFilesPath_[0] + ".go-memcached.index"
		}
		cache, err = config.OpenCache(true)
		if err != nil {
			log.Fatalf("Cannot open cache: [%s]", err)
		}
	} else if cacheFilesCount > 1 {
		config.MaxItemsCount /= ybc.SizeT(cacheFilesCount)
		config.DataFileSize /= ybc.SizeT(cacheFilesCount)
		var configs ybc.ClusterConfig
		configs = make([]*ybc.Config, cacheFilesCount)
		for i := 0; i < cacheFilesCount; i++ {
			cfg := config
			cfg.DataFile = cacheFilesPath_[i] + ".go-memcached.data"
			cfg.IndexFile = cacheFilesPath_[i] + ".go-memcached.index"
			configs[i] = &cfg
		}
		cache, err = configs.OpenCluster(true)
		if err != nil {
			log.Fatalf("Cannot open cache cluster: [%s]", err)
		}
	}
	defer cache.Close()
	log.Printf("Data files have been opened\n")

	s := memcache.Server{
		Cache:             cache,
		ListenAddr:        *listenAddr,
		ReadBufferSize:    *readBufferSize,
		WriteBufferSize:   *writeBufferSize,
		OSReadBufferSize:  *osReadBufferSize,
		OSWriteBufferSize: *osWriteBufferSize,
	}
	log.Printf("Starting the server")
	if err := s.Serve(); err != nil {
		log.Fatalf("Cannot serve traffic: [%s]", err)
	}
}
开发者ID:kangkot,项目名称:ybc,代码行数:65,代码来源:main.go


注:本文中的github.com/valyala/ybc/bindings/go/ybc.Config.DataFileSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。