Giter VIP home page Giter VIP logo

Comments (5)

longyue0521 avatar longyue0521 commented on June 16, 2024

之所以用ctx是想表达在成功调用ShutdownNow那一刻,所有处于“可中断上下文”中的go协程均能收到中断信号.这其中不仅包括了schedulingTasks任务调度循环,还包括那些运行中且内部监听了ctx信号的Task

func (b *OnDemandBlockTaskPool) schedulingTasks() {
                                  // .....

				// 这里向task传递的正是那个ctx,对于那些在内部监听了ctx.Done()的Task
                                  // 使其以自定义方式更快速地中断运行
				err := task.Run(b.ctx)
				if err != nil {
					return
				}
			}()
		}
	}
}

https://github.com/gotomicro/ekit/blob/dev/pool/task_pool.go#L253

from ekit.

flycash avatar flycash commented on June 16, 2024

👍
我试了一下别的方式,比如说使用 channel,确实不如这种方法好。

from ekit.

kangdan6 avatar kangdan6 commented on June 16, 2024

@longyue0521 @flycash 有几点疑问,请大佬指点:
1、NewOnDemandBlockTaskPool时用户必须使用WithQueueBacklogRate这个options来设置queueBacklogRate吗?否则if判断queueBacklogRate默认值为0,会创建失败吧?

2、372行注释不对吧(刚启动的协程除非恰巧赶上Shutdown/ShutdownNow被调用,否则应该至少执行一个task),如果initGo是10,用户只提交了2个任务,那剩余8个goroutine不会执行任务,所以不会至少执行一个task吧

from ekit.

longyue0521 avatar longyue0521 commented on June 16, 2024

@kangdan6

  1. 既然设置为options,必然是可选的.即用户不通过WithXXXOption指定,在New的时候会提供默认值. 你可以看一下对应的测试代码,也可以在本地构造一个不设置queueBacklogRate而使NewOnDemandBlockTaskPool失败的测试用例
  2. 这个注释是用来说明,为什么刚刚创建idleTimer就要将其关闭,因为刚创建出来的协程很可能直接走for循环中的case <-idleTimer.C分支而退出. 那么这样耗时、耗资源创建出的协程却什么都没干是没有意义的.你举的用例是因为提供足够的任务,但也确实反映出该注视确实会引起歧义.你可以提交一个issue修改/完善该注释.

from ekit.

kangdan6 avatar kangdan6 commented on June 16, 2024

from ekit.

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.