小编Phi*_*EUR的帖子

无法避免在CPU上单独启动的进程上的上下文切换

我正在调查如何在专用CPU上运行进程以避免上下文切换.在我的Ubuntu上,我使用内核参数"isolcpus = 3,7"和"irqaffinity = 0-2,4-6"隔离了两个CPU.我确信它已被正确考虑到:

$ cat /proc/cmdline 
BOOT_IMAGE=/boot/vmlinuz-4.8.0-27-generic root=UUID=58c66f12-0588-442b-9bb8-1d2dd833efe2 ro quiet splash isolcpus=3,7 irqaffinity=0-2,4-6 vt.handoff=7
Run Code Online (Sandbox Code Playgroud)

重启后,我可以检查一切是否按预期工作.在我运行的第一个控制台上

$ stress -c 24
stress: info: [31717] dispatching hogs: 24 cpu, 0 io, 0 vm, 0 hdd
Run Code Online (Sandbox Code Playgroud)

在第二个,使用"顶部"我可以检查我的CPU的使用情况:

top - 18:39:07 up 2 days, 20:48, 18 users,  load average: 23,15, 10,46, 4,53
Tasks: 457 total,  26 running, 431 sleeping,   0 stopped,   0 zombie
%Cpu0  :100,0 us,  0,0 sy,  0,0 ni,  0,0 id,  0,0 wa,  0,0 hi,  0,0 si,  0,0 st
%Cpu1  : 98,7 …
Run Code Online (Sandbox Code Playgroud)

performance scheduler affinity context-switch linux-kernel

6
推荐指数
2
解决办法
1083
查看次数

Java中的并发和可伸缩数据结构来处理任务?

对于我当前的开发,我有很多线程(Producers)创建Tasks和许多线程消耗这些Tasks(consumers)

每个Producers都由一个唯一的名称标识; A Tasks由以下部分组成:

  • 它的名字 Producers
  • 一个名字
  • 数据

我的问题涉及(Producers)和(consumers)使用的数据结构.

并发队列?

天真地,我们可以想象Producers使用Tasks和(consumers)读取/消耗Tasks存储在并发队列中的并发队列.

我认为这个解决方案相当规模,但是单个案例是有问题的:如果a Producers创建非常快,两个Tasks具有相同的名称但不是相同的数据(任务T1和T2具有相同的名称但T1具有数据D1和T2具有数据D2),理论上可能它们按T2然后T1的顺序消耗!

任务图+队列?

现在,我想MyQueue基于Map + Queue 创建自己的数据结构(比方说).比如一个队列,它会有一个pop()和一个push()方法.

  • pop()方法非常简单
  • push()方法将:
    • 检查是否Task尚未插入现有MyQueue(find()在地图中执行)
      • 如果找到:存储在Task待插入中的数据将与存储在找到的数据中合并Task
      • 如果没有找到:Task将插入地图中,并在队列中添加一个条目

当然,我必须安全地进行并发访问......这肯定是我的问题; 我几乎可以肯定这个解决方案不会扩展.

所以呢?

所以我现在的问题是,为了满足我的要求,我必须使用哪种最佳数据结构

java concurrency multithreading scalability data-structures

6
推荐指数
1
解决办法
385
查看次数

SpringBoot:如何注入两个具有相同名称的类

在我的应用程序中,我有两个具有相同名称的类,但当然位于不同的包中。

这两个类都需要注入到应用程序中;不幸的是,我收到以下错误消息:

Caused by: org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'myFeature' for bean class [org.pmesmeur.springboot.training.service.feature2.MyFeature] conflicts with existing, non-compatible bean definition of same name and class [org.pmesmeur.springboot.training.service.feature1.MyFeature]
Run Code Online (Sandbox Code Playgroud)

我的问题可以通过以下示例重现:

@Component
@EnableConfigurationProperties(ServiceProperties.class)
public class MyService implements IService {

    private final ServiceProperties serviceProperties;
    private final IProvider provider;
    private final org.pmesmeur.springboot.training.service.feature1.IMyFeature f1;
    private final org.pmesmeur.springboot.training.service.feature2.IMyFeature f2;


    @Autowired
    public MyService(ServiceProperties serviceProperties,
                     IProvider provider,
                     org.pmesmeur.springboot.training.service.feature1.IMyFeature f1,
                     org.pmesmeur.springboot.training.service.feature2.IMyFeature f2) {
        this.serviceProperties = serviceProperties;
        this.provider = provider;
        this.f1 = f1;
        this.f2 = f2;
    }
    ...
Run Code Online (Sandbox Code Playgroud)
package org.pmesmeur.springboot.training.service.feature1;

public interface IMyFeature …
Run Code Online (Sandbox Code Playgroud)

spring dependency-injection guice spring-boot

5
推荐指数
1
解决办法
7128
查看次数

如何在系统中创建线程时通知

我想创建一个C/C++程序,当在系统中创建一个线程(而不是在当前进程中)时,它会"实时"通知(即尽可能快):

  • 现有流程中的新线程
  • 新进程

我想在Linux上使用解决方案.如果它可以在任何UNIX上移植,那就更好了.

  • 我可以使用POSIX API吗?
  • 是否有可能从"任何地方"获取此信息/sys/kernel
  • 还有其他方法吗?

c multithreading posix pthreads linux-kernel

2
推荐指数
1
解决办法
102
查看次数