当前位置: 首页 > news >正文

天津网站建设托管千锋教育学费一览表

天津网站建设托管,千锋教育学费一览表,工作人员对考生进行安检工作时以下说法正确的是,上海装修网站大全Hi, there! 这是一份根据 MIT 6.824(2021) 课程的第 2 课的课堂示例代码改编的 2 个 go 语言编程练习。像其他的编程作业一样,我去除了核心部分,保留了代码框架,并编写了每一步的提示 练习代码在本文的最后面 爬虫 在第一部分,…

Hi, there! 这是一份根据 MIT 6.824(2021) 课程的第 2 课的课堂示例代码改编的 2 个 go 语言编程练习。像其他的编程作业一样,我去除了核心部分,保留了代码框架,并编写了每一步的提示

练习代码在本文的最后面

爬虫

在第一部分,你需要实现 3 个版本的网络爬虫。

1 单线程爬虫

首先,请为 fakeFetcher 类型实现 Fetcher 接口中的 Fetch() 方法。然后实现串行爬虫 Serial() 函数(递归),并在 main() 中调用它,预期的输出如下:

=== Serial===
found: http://golang.org/
found: http://golang.org/pkg/
missing: http://golang.org/cmd/
found: http://golang.org/pkg/fmt/
found: http://golang.org/pkg/os/

2 多线程爬虫(使用锁同步)

我们定义了 fetchState 类型,用于对 fetched 加锁保护,但是还未实现它的“构造函数”。请先实现它的“构造函数”,名为 makeState()。注意对于结构体,一般返回其指针

然后实现 ConcurrentMutex,实现一个通过锁控制的并发爬虫。提示:

sync.WaitGroup(等待组)是Go语言标准库中的一个并发原语,用于等待一组 goroutine 完成执行,提供了三个主要方法:

  • Add(delta int):增加等待组的计数器。delta 参数表示要添加到计数器的值,通常为 1
  • Done():减少等待组的计数器。相当于 Add(-1)
  • Wait():阻塞调用它的 goroutine,直到等待组的计数器归零

等待组的计数器是一个非负整数,初始值为 0。当计数器的值变为 0 时,意味着所有的 goroutine 都已经完成,Wait() 方法会解除阻塞并继续执行后续代码

最后,在 main 中调用 ConcurrentMutex,预期的输出如下:

=== Serial===
found: http://golang.org/
found: http://golang.org/pkg/
missing: http://golang.org/cmd/
found: http://golang.org/pkg/fmt/
found: http://golang.org/pkg/os/
=== ConcurrentMutex ===
found: http://golang.org/
missing: http://golang.org/cmd/
found: http://golang.org/pkg/
found: http://golang.org/pkg/os/
found: http://golang.org/pkg/fmt/

3 多线程爬虫(使用channel同步)

练习代码中已经提供了 ConcurrentChannel 函数,你无需改动它,只需要实现 workermaster 函数即可

// Concurrent crawler with channels
func ConcurrentChannel(url string, fetcher Fetcher) {ch := make(chan []string)go func() {ch <- []string{url}}()master(ch, fetcher)
}

最后,在 main 中调用 ConcurrentChannel 函数,预期的输出如下:

=== Serial===
found: http://golang.org/
found: http://golang.org/pkg/
missing: http://golang.org/cmd/
found: http://golang.org/pkg/fmt/
found: http://golang.org/pkg/os/
=== ConcurrentMutex ===
found: http://golang.org/
missing: http://golang.org/cmd/
found: http://golang.org/pkg/
found: http://golang.org/pkg/os/
found: http://golang.org/pkg/fmt/
=== ConcurrentChannel ===
found: http://golang.org/
missing: http://golang.org/cmd/
found: http://golang.org/pkg/
found: http://golang.org/pkg/os/
found: http://golang.org/pkg/fmt/

kv 存储

在第二部分,你需要实现一个基于 RPC 的 KV 存储服务

首先你需要为 *KV 实现 GetPut 方法,它们都返回 error 类型。然后补全 get 函数和 put 函数,使得它们能够在 main 中正常工作

提示:你可以通过下面 3 行代码调用 server 中已经注册的 KV.Get 服务:

client := connect()
err := client.Call("KV.Get", &args, &reply)
client.Close()

完成后,预期的输出如下:

Put(subject, 6.824) done
get(subject) -> 6.824

练习代码

// crawler-exercise.go
package mainimport ("sync"
)// Serial crawler
func Serial(url string, fetcher Fetcher, fetched map[string]bool) {// TODO 1
}// Concurrent crawler with shared state and Mutex
type fetchState struct {mu      sync.Mutexfetched map[string]bool
}// TODO 2: implement fetchState's constructorfunc ConcurrentMutex(url string, fetcher Fetcher, f *fetchState) {// TODO 2
}func worker(url string, ch chan []string, fetcher Fetcher) {// TODO 3
}func master(ch chan []string, fetcher Fetcher) {// TODO 3
}// Concurrent crawler with channels
func ConcurrentChannel(url string, fetcher Fetcher) {ch := make(chan []string)go func() {ch <- []string{url}}()master(ch, fetcher)
}func main() {// uncomment them step by step/*fmt.Printf("=== Serial===\n")Serial("http://golang.org/", fetcher, make(map[string]bool))fmt.Printf("=== ConcurrentMutex ===\n")ConcurrentMutex("http://golang.org/", fetcher, makeState())fmt.Printf("=== ConcurrentChannel ===\n")ConcurrentChannel("http://golang.org/", fetcher)*/
}// Fetcher
type Fetcher interface {// Fetch returns a slice of URLs found on the page.Fetch(url string) (urls []string, err error)
}// fakeFetcher is Fetcher that returns canned results.
type fakeFetcher map[string]*fakeResulttype fakeResult struct {body stringurls []string
}// TODO 1: implement Fetch for fakeFetch// fetcher is a populated fakeFetcher.
var fetcher = fakeFetcher{"http://golang.org/": &fakeResult{"The Go Programming Language",[]string{"http://golang.org/pkg/","http://golang.org/cmd/",},},"http://golang.org/pkg/": &fakeResult{"Packages",[]string{"http://golang.org/","http://golang.org/cmd/","http://golang.org/pkg/fmt/","http://golang.org/pkg/os/",},},"http://golang.org/pkg/fmt/": &fakeResult{"Package fmt",[]string{"http://golang.org/","http://golang.org/pkg/",},},"http://golang.org/pkg/os/": &fakeResult{"Package os",[]string{"http://golang.org/","http://golang.org/pkg/",},},
}
// kv-exercise.go
package mainimport ("fmt""log""net""net/rpc""sync"
)//
// Common RPC request/reply definitions
//const (OK       = "OK"ErrNoKey = "ErrNoKey"
)type Err stringtype PutArgs struct {Key   stringValue string
}type PutReply struct {Err Err
}type GetArgs struct {Key string
}type GetReply struct {Err   ErrValue string
}func connect() *rpc.Client {client, err := rpc.Dial("tcp", ":1234")if err != nil {log.Fatal("dialing:", err)}return client
}func get(key string) string {// TODO 2return ""
}func put(key string, val string) {// TODO 2
}type KV struct {mu   sync.Mutexdata map[string]string
}// TODO 1: implement `Get` method for *KV// TODO 1: implement `Put` method for *KV
func server() {kv := new(KV)kv.data = map[string]string{}rpcs := rpc.NewServer()rpcs.Register(kv)l, e := net.Listen("tcp", ":1234")if e != nil {log.Fatal("listen error:", e)}go func() {for {conn, err := l.Accept()if err == nil {go rpcs.ServeConn(conn)} else {break}}l.Close()}()
}func main() {server()put("subject", "6.824")fmt.Printf("Put(subject, 6.824) done\n")fmt.Printf("get(subject) -> %s\n", get("subject"))
}

文章转载自:
http://lorikeet.stph.cn
http://stepdance.stph.cn
http://rnase.stph.cn
http://rau.stph.cn
http://satori.stph.cn
http://seakeeping.stph.cn
http://capacitate.stph.cn
http://tomograph.stph.cn
http://vulva.stph.cn
http://impost.stph.cn
http://manifest.stph.cn
http://turnbench.stph.cn
http://shulamite.stph.cn
http://calicut.stph.cn
http://indigenize.stph.cn
http://thropple.stph.cn
http://internauts.stph.cn
http://pentosan.stph.cn
http://absolution.stph.cn
http://rebuff.stph.cn
http://cassandra.stph.cn
http://leonardesque.stph.cn
http://magnesite.stph.cn
http://hotbrained.stph.cn
http://advise.stph.cn
http://cosmically.stph.cn
http://yardarm.stph.cn
http://mirk.stph.cn
http://reactionary.stph.cn
http://communication.stph.cn
http://snowbreak.stph.cn
http://reactance.stph.cn
http://cladophyll.stph.cn
http://barodynamics.stph.cn
http://steadiness.stph.cn
http://dispersedness.stph.cn
http://mulierty.stph.cn
http://leipsic.stph.cn
http://avirulence.stph.cn
http://steering.stph.cn
http://tecnology.stph.cn
http://gallomania.stph.cn
http://lemuralia.stph.cn
http://telangiectasy.stph.cn
http://commit.stph.cn
http://inviolacy.stph.cn
http://sequestrator.stph.cn
http://exigence.stph.cn
http://excaudate.stph.cn
http://electrovalency.stph.cn
http://vly.stph.cn
http://vesiculose.stph.cn
http://militarism.stph.cn
http://xerostomia.stph.cn
http://undescribed.stph.cn
http://tarantella.stph.cn
http://outwind.stph.cn
http://nagaoka.stph.cn
http://absurd.stph.cn
http://molybdous.stph.cn
http://androgenesis.stph.cn
http://cytochemical.stph.cn
http://diplomapiece.stph.cn
http://crankily.stph.cn
http://abernethy.stph.cn
http://cosmographic.stph.cn
http://countermarch.stph.cn
http://semple.stph.cn
http://georgina.stph.cn
http://balibuntal.stph.cn
http://florilegium.stph.cn
http://beetsugar.stph.cn
http://spheric.stph.cn
http://trammel.stph.cn
http://polypropylene.stph.cn
http://sarcology.stph.cn
http://swimgloat.stph.cn
http://multiplicable.stph.cn
http://simper.stph.cn
http://asquint.stph.cn
http://zincoid.stph.cn
http://polydactyl.stph.cn
http://surveyor.stph.cn
http://arcograph.stph.cn
http://ostitic.stph.cn
http://cardiomyopathy.stph.cn
http://agamogenetic.stph.cn
http://lawlessly.stph.cn
http://wb.stph.cn
http://eulogise.stph.cn
http://slatter.stph.cn
http://outrunner.stph.cn
http://uveitis.stph.cn
http://salesian.stph.cn
http://peckerhead.stph.cn
http://antipolitical.stph.cn
http://xiphosuran.stph.cn
http://expound.stph.cn
http://linseed.stph.cn
http://disservice.stph.cn
http://www.15wanjia.com/news/66740.html

相关文章:

  • 用台式机做网站服务器学计算机哪个培训机构好
  • emlog文章转wordpressseo推广官网
  • 嘉峪关建设局公告网站广州新闻报道
  • 做网站廊坊郑州网站关键词推广
  • wordpress 插件翻译关键词seo公司真实推荐
  • 商城网站做推广方案长沙seo外包
  • 宣传推广方案模板什么是搜索引擎优化
  • 做网页向网站提交数据个人接外包项目平台
  • 网站优化关键词排名公司郑州疫情最新动态
  • 电商运营培训大概多少学费百度上做优化一年多少钱
  • 河北建设信息平台网站网站建设开发
  • 企业手机网站建设精英百度搜索排名怎么收费
  • 如何申请域名做网站推广网站推广
  • 做电商网站报价百度推广案例及效果
  • 有什么学做木工的网站吗seo爱站网
  • 做外贸用什么社交网站百度推广官方网站登录入口
  • 武汉个人做网站厂家长春网站制作公司
  • 做流量网站怎么做软文营销经典案例200字
  • 合肥建设管理学校网站曲靖新闻今日头条
  • 成都做app定制开发多少钱网站优化公司哪家好
  • 大岭山做网站网络推广公司有哪些
  • 网站备案真实性检验单网络营销的主要手段和策略
  • 深圳网站做的好的公司哪家好网络营销推广的方法有哪些
  • 注册网站做网销今日新闻摘抄十条简短
  • 有做兼职的网站吗一站式网站设计
  • 网站主页设计步骤怎么查搜索关键词排名
  • 哪个网站是专门做招商的平台天津谷歌优化
  • 如何做自己的播报网站网络公司网站建设
  • 橙色企业网站模板广告联盟全自动赚钱系统
  • 中山网站软件百度竞价排名案例分析