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

One CPU Core Pinned at 100%? #8

Open
djthread opened this issue Jan 8, 2017 · 2 comments · May be fixed by #13
Open

One CPU Core Pinned at 100%? #8

djthread opened this issue Jan 8, 2017 · 2 comments · May be fixed by #13

Comments

@djthread
Copy link

djthread commented Jan 8, 2017

Much thanks for sharing this library! It was great to find it as I set about trying to read some buttons on my controller. What I noticed, though, is that as soon as I run this line in iex

iex(1)> {:ok, input} = PortMidi.open(:input, "Midi Fighter 3D MIDI 1")
{:ok, #PID<0.177.0>}

... I get one of my cores pinned to 100%

It does seem to work alright otherwise, but something is clearly wrong. And thoughts on what it might be?

defmodule Test do
  @dev_name "Midi Fighter 3D MIDI 1"

  def start do
    {:ok, input} = PortMidi.open(:input, @dev_name)
    :ok = PortMidi.listen(input, self)
    go
  end

  def go do
    receive do
      msg ->
        IO.inspect msg
        go
    end
  end
end

Launching this and moving some controls does give me the messages back, but my CPU is working awfully hard for it.

iex(1)> Test.start
{#PID<0.177.0>, [{{146, 48, 127}, 4417}]}
{#PID<0.177.0>, [{{130, 48, 127}, 4534}]}

This is on an Arch Linux system.

@lucidstack
Copy link
Owner

lucidstack commented Jan 12, 2017

Hey there, thank you for using ex-portmidi! Sorry about this (and for taking long to answer). It looks like we're gonna need a sleep call in portmidi's poll loop, to give some CPU time to the system.

I'll give this a try and let you know as soon as you can pull a new version! 🙇

@djthread
Copy link
Author

Thank you for the response, @lucidstack! I'm glad you can corroborate my finding. I wonder if there might be some way to do a select on the socket somehow and avoid putting a sleep in the loop. I have no idea of the challenges in portmidi nor interfacing with it, but it's my understanding that putting a sleep in the main loop not really the best option.

For my little toy project here, I'm looking to map buttons on my Midi Fighter 3D to control my home server / living room. Being another process on my low power, multi-purpose server, I'd be concerned with adding unnecessary cpu work...

At any rate, I really appreciate your working on and sharing this library. It was really great to find.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants