有人可以解释SCHED_OTHER,SCHED_FIFO和SCHED_RR之间的区别吗?
谢谢
我正在研究Ubuntu项目.没有找到sched_batch和sched_other之间的明显区别.有人能告诉我区别吗?
如何找到multiprocessing.Pool实例的最佳块大小?
之前我用过这个来创建一个nsudoku对象的生成器:
processes = multiprocessing.cpu_count()
worker_pool = multiprocessing.Pool(processes)
sudokus = worker_pool.imap_unordered(create_sudoku, range(n), n // processes + 1)
Run Code Online (Sandbox Code Playgroud)
为了测量时间,我time.time()在上面的片段之前使用,然后按照描述初始化池,然后我将生成器转换为list(list(sudokus))以触发生成项目(仅用于时间测量,我知道这在最终程序中是无意义的),然后我time.time()再次使用时间并输出差异.
我观察到每个对象的块大小n // processes + 1约为0.425毫秒.但我也观察到CPU只在整个过程的前半部分完全加载,最终使用率下降到25%(在具有2核和超线程的i3上).
如果我使用较小的块大小int(l // (processes**2) + 1),我会得到大约0.355毫秒的时间,并且CPU负载分布更好.它只有一些小的尖峰到ca. 75%,但在处理时间的长时间内保持高位,然后降至25%.
是否有更好的公式来计算块大小或更好的方法来使用CPU最有效?请帮助我提高这个多处理池的有效性.
performance multiprocessing python-3.x python-multiprocessing
编写简单的 C 代码,尝试控制两个不同线程的输出:
#include <pthread.h>
#include <semaphore.h>
#include <stdio.h>
sem_t sem;
void* thread_func(void* aArgs)
{
printf("Entering thread %p with %d\n", (void*)pthread_self(), (int)aArgs);
int i = 0;
for(;i < 10; i++)
{
sem_wait(&sem);
if ((i % 2) == (int)aArgs)
printf("val is %d in thread %p \n", i, (void*)pthread_self());
sem_post(&sem);
}
}
int main()
{
pthread_t thread_1, thread_2;
sem_init(&sem, 0, 1);
pthread_create(&thread_1, NULL, (void*)thread_func, (void*)0);
pthread_create(&thread_2, NULL, (void*)thread_func, (void*)1);
pthread_join(thread_1, NULL);
pthread_join(thread_2, NULL);
sem_destroy(&sem);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我想要实现的是混合奇数和偶数的序列。但我从一个线程接收所有数字,然后从第二个线程接收所有其他数字,如下所示(即使我增加循环计数器幅度):
Entering thread 0xb75f2b40 with …Run Code Online (Sandbox Code Playgroud) 我知道调度是由内核完成的.让我们假设Linux中的进程(P1)当前正在处理器上执行.由于当前进程对时间片一无所知并且内核当前没有在处理器上执行,因此内核如何安排下一个进程执行?
是否有某种中断告诉处理器切换执行内核或任何其他机制?
对于我的应用程序,需要一个每 1us 记录一个以太网帧的函数。可以用 python/threading 来做吗?
我使用 threading.Timer 获得的最大延迟接近 10 毫秒。
python multithreading ethernet python-multithreading python-3.x
linux ×3
scheduling ×3
python-3.x ×2
c ×1
cfs ×1
ethernet ×1
linux-kernel ×1
performance ×1
process ×1
processor ×1
pthreads ×1
python ×1
scheduler ×1