Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can you add a name_prefix method to 0.2 runtime ’s builder? #1907

Closed
biluohc opened this issue Dec 6, 2019 · 5 comments · Fixed by #1921
Closed

Can you add a name_prefix method to 0.2 runtime ’s builder? #1907

biluohc opened this issue Dec 6, 2019 · 5 comments · Fixed by #1921
Labels
A-tokio Area: The main tokio crate C-feature-accepted Category: A feature request that has been accepted pending implementation. C-feature-request Category: A feature request. M-runtime Module: tokio/runtime

Comments

@biluohc
Copy link
Contributor

biluohc commented Dec 6, 2019

https://docs.rs/tokio/0.2.2/tokio/runtime/struct.Builder.html#method.thread_name

https://docs.rs/tokio/0.1.21/tokio/runtime/struct.Builder.html#method.name_prefix

Why is the name_prefix of 0.1 replaced by the thread_name of 0.2?
I need different thread names to help track task running,incremental id of 0.1 is good.

@biluohc
Copy link
Contributor Author

biluohc commented Dec 6, 2019

Or store a closure as a thread name producer?

@carllerche carllerche added the C-enhancement Category: A PR with an enhancement or bugfix. label Dec 6, 2019
@biluohc
Copy link
Contributor Author

biluohc commented Dec 6, 2019

@hawkw
Eliza Weisman: Hi @biluohc, I believe that if you pass a string to thread_name, it is still the prefix, as in 0.1.

Thandks for your repl, but looks no effect(Ubuntu 16.04, 1.39 stable, master branch tokio).

    let mut rt = tokio::runtime::Builder::new()
        .num_threads(3)
        .threaded_scheduler()
        .thread_name("tok-")
        .enable_all()
        .build()
        .unwrap();
top - 15:03:08 up 133 days,  3:07,  4 users,  load average: 0.38, 0.37, 0.46
Threads:   5 total,   0 running,   5 sleeping,   0 stopped,   0 zombie
%Cpu(s):  3.9 us,  2.7 sy,  0.0 ni, 91.4 id,  1.9 wa,  0.0 hi,  0.1 si,  0.0 st
KiB Mem : 32946936 total,   331500 free, 15747280 used, 16868156 buff/cache
KiB Swap:        0 total,        0 free,        0 used. 16646908 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND
13036 xxx      20   0  295.5m  14.0m   2.2m S  0.0  0.0   0:00.99 toks-threaded2
13039 xxx      20   0  295.5m  14.0m   2.2m S  0.0  0.0   0:00.00 log
13040 xxx      20   0  295.5m  14.0m   2.2m S  0.0  0.0   0:20.78 tok-
13041 xxx     20   0  295.5m  14.0m   2.2m S  0.0  0.0   0:20.83 tok-
13042 xxx      20   0  295.5m  14.0m   2.2m S  0.0  0.0   0:20.84 tok-

I only found it about thread::Builder::name from tokio(Master branch):

src/runtime/blocking/pool.rs
5:use crate::runtime::{self, io, time, Builder, Callback};
99:        builder: &Builder,
239:        let mut builder = thread::Builder::new().name(self.inner.thread_name.clone());

@carllerche
Copy link
Member

An Fn to name threads is ok but it would need to be Send + Sync + ‘static

@biluohc
Copy link
Contributor Author

biluohc commented Dec 6, 2019

Of course it should be Send + Sync + ‘static.

But if to implement it, should add an api (maybe thread_name_generator?) or just modify the existing method directly(thread_name)?

@carllerche
Copy link
Member

Maybe just thread_name_fn? dunno, i'm open to suggestions :)

biluohc added a commit to biluohc/tokio that referenced this issue Dec 7, 2019
biluohc added a commit to biluohc/tokio that referenced this issue Mar 3, 2020
biluohc added a commit to biluohc/tokio that referenced this issue Mar 3, 2020
Co-Authored-By: Eliza Weisman <eliza@buoyant.io>
biluohc added a commit to biluohc/tokio that referenced this issue Mar 3, 2020
Co-Authored-By: Eliza Weisman <eliza@buoyant.io>
biluohc added a commit to biluohc/tokio that referenced this issue Apr 10, 2020
Co-Authored-By: Eliza Weisman <eliza@buoyant.io>
@Darksonn Darksonn added A-tokio Area: The main tokio crate C-feature-accepted Category: A feature request that has been accepted pending implementation. C-feature-request Category: A feature request. M-runtime Module: tokio/runtime and removed C-enhancement Category: A PR with an enhancement or bugfix. labels Jul 25, 2020
biluohc added a commit to biluohc/tokio that referenced this issue Aug 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate C-feature-accepted Category: A feature request that has been accepted pending implementation. C-feature-request Category: A feature request. M-runtime Module: tokio/runtime
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants