solanav

solanav

Hello everyone!

I’m currently working on a web spider/metadata extractor and because writing parsers for many file types would be too much work, I’m using libextractor.

I wrote a NIF which I learned only allows for functions that return in less than ~1ms. So I just changed this:

static ErlNifFunc funcs[] = {
  { "extract", 2, extract }
};

into this:

static ErlNifFunc funcs[] = {
  { "extract", 2, extract, ERL_NIF_DIRTY_JOB_CPU_BOUND }
};

The problem: it seems like the scheduler gets to 100% utilization which is bad because the spider downloads a lot of files in parallel so it becomes impossible to do things like launch the observer if I’m calling the NIF. Any idea if this is normal? Is there a way I can prevent the NIF from blocking the rest of the system?

Here is a picture of the observer while I test the calls to my main function:

Thanks!

Showing Posts 1 to 10

mpope

mpope

Is it possible to run erlang:system_info to check schedulers_state, scheduling_statistics, dirty_cpu_schedulers_online, dirty_cpu_schedulers

And the most useful would be to check schedulers using microstate accounting? msacc:start(1000), msacc:print(), msacc:stop(). Might not be wise to use it in a production env…

ityonemo

ityonemo

Can you set the number of dirty nif schedulers to number of cores - 1? Probably easiest way to test this is to do the following at startup:

:erlang.system_flag(:dirty_cpu_schedulers, System.schedulers_online() - 1)
NobbZ

NobbZ

Are you sure that your NIF is CPU bound and not IO bound?

solanav

solanav OP

I don’t know how useful this is, I’m just running iex -S mix on my NIF, it’s not running in production or anything, but I hope it helps.

Is it possible to run erlang:system_info to check schedulers_state, scheduling_statistics, dirty_cpu_schedulers_online, dirty_cpu_schedulers

iex(1)> {:ok, file_data} = File.read("/home/solanav/krptkn/final_form.png")
{:ok,
 <<137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 6, 50, 0,
   0, 2, 229, 8, 6, 0, 0, 0, 110, 46, 127, 76, 0, 0, 11, 218, 116, 69, 88, 116,
   109, 120, 102, 105, 108, 101, 0, ...>>}

iex(2)> Extractor.extract(file_data)
Extracting plugins...[OK] [0.046875]
Reading file binary...[OK] [0.000000]
Extracting the data...[OK] [0.218750]
Removing the plugins...[OK] [0.000000]
Creating list of data...[OK] [0.000000]
Destroying the data array...[OK] [0.000000]
[
  {'png', 'mimetype', 1, 'text/plain', 'image/png'},
  {'png', 'image dimensions', 1, 'text/plain', '1586x741'},
  {'mime', 'mimetype', 1, 'text/plain', 'image/png'},
  {'png', 'keywords', 1, 'text/plain', 'url encoded data'},
  {'thumbnailgtk', 'image dimensions', 1, 'text/plain', '1586x741'},
  {'thumbnailgtk', 'thumbnail', 2, 'image/png',  [137, 80, 78, 71, 13, 10, 26, 10]},
  {'gstreamer', 'mimetype', 1, 'text/plain', 'image/png'},
  {'gstreamer', 'video dimensions', 1, 'text/plain', '1586x741'},
  {'gstreamer', 'video depth', 1, 'text/plain', '32'},
  {'gstreamer', 'pixel aspect ratio', 1, 'text/plain', '1/1'}
]

iex(3)> :erlang.system_info(:schedulers_state)
{12, 12, 12}

iex(4)> :erlang.system_info(:scheduling_statistics)
[
  {:process_max, 0, 0},
  {:process_high, 0, 0},
  {:process_normal, 0, 0},
  {:process_low, 0, 0},
  {:port, 0, 0}
]

iex(5)> :erlang.system_info(:dirty_cpu_schedulers_online)
12

iex(6)> :erlang.system_info(:dirty_cpu_schedulers)
12

And the most useful would be to check schedulers using microstate accounting? msacc:start(1000), msacc:print(), msacc:stop(). Might not be wise to use it in a production env…

Here I did :msacc.start(1000), ran the NIF, printed and then stopped.

iex(8)> :msacc.print()
Average thread real-time    : 1001601 us
Accumulated system run-time :    7208 us
Average scheduler run-time  :     593 us

        Thread      aux check_io emulator       gc    other     port    sleep

Stats per thread:
     async( 0)    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%  100.00%
       aux( 1)    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%   99.99%
dirty_cpu_( 1)    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%  100.00%
dirty_cpu_( 2)    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%  100.00%
dirty_cpu_( 3)    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%  100.00%
dirty_cpu_( 4)    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%  100.00%
dirty_cpu_( 5)    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%  100.00%
dirty_cpu_( 6)    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%  100.00%
dirty_cpu_( 7)    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%  100.00%
dirty_cpu_( 8)    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%  100.00%
dirty_cpu_( 9)    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%  100.00%
dirty_cpu_(10)    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%  100.00%
dirty_cpu_(11)    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%  100.00%
dirty_cpu_(12)    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%  100.00%
dirty_io_s( 1)    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%  100.00%
dirty_io_s( 2)    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%  100.00%
dirty_io_s( 3)    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%  100.00%
dirty_io_s( 4)    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%  100.00%
dirty_io_s( 5)    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%  100.00%
dirty_io_s( 6)    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%  100.00%
dirty_io_s( 7)    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%  100.00%
dirty_io_s( 8)    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%  100.00%
dirty_io_s( 9)    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%  100.00%
dirty_io_s(10)    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%  100.00%
      poll( 0)    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%  100.00%
 scheduler( 1)    0.00%    0.05%    0.00%    0.00%    0.00%    0.00%   99.94%
 scheduler( 2)    0.00%    0.00%    0.00%    0.00%    0.06%    0.00%   99.94%
 scheduler( 3)    0.00%    0.00%    0.00%    0.00%    0.06%    0.00%   99.94%
 scheduler( 4)    0.00%    0.00%    0.00%    0.00%    0.07%    0.00%   99.93%
 scheduler( 5)    0.00%    0.00%    0.00%    0.00%    0.06%    0.00%   99.94%
 scheduler( 6)    0.00%    0.00%    0.00%    0.00%    0.06%    0.00%   99.94%
 scheduler( 7)    0.00%    0.00%    0.00%    0.00%    0.01%    0.00%   99.99%
 scheduler( 8)    0.00%    0.00%    0.00%    0.00%    0.06%    0.00%   99.94%
 scheduler( 9)    0.00%    0.00%    0.00%    0.00%    0.06%    0.00%   99.94%
 scheduler(10)    0.00%    0.00%    0.00%    0.00%    0.06%    0.00%   99.94%
 scheduler(11)    0.00%    0.00%    0.00%    0.00%    0.06%    0.00%   99.94%
 scheduler(12)    0.00%    0.00%    0.00%    0.00%    0.06%    0.00%   99.94%

Stats per type:
         async    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%  100.00%
           aux    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%   99.99%
dirty_cpu_sche    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%  100.00%
dirty_io_sched    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%  100.00%
          poll    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%  100.00%
     scheduler    0.00%    0.00%    0.00%    0.00%    0.05%    0.00%   99.94%
:ok
solanav

solanav OP

So I tried doing that and it seems like the result is the same, probably because the number of dirty schedulers was 12 so I guess not much changed.

solanav

solanav OP

Well I am not. Not really. I know libextractor (the library I am wrapping with this NIF) does not wait for user input and does not connect to the internet. But I think it may be running some code stored on dynamic libraries.

But I have tried changing it to IO scheduler and even though the peak was of less duration, it still peaked at 80-100%. The graph was almost the same but no dotted line, just a normal one.

nonblockio

nonblockio

It seems that the performance surge only least for one or two seconds from the chart. :msacc.start(1000) is kinda too short to catch the vibration since it only analyze scheduler in 1000ms. Could you increase the time of :msacc.start/1 and try to fit the surge in that period?

nonblockio

nonblockio

And could you provide the OTP version?

solanav

solanav OP

I’m using version 23.1 (tried both on WSL and on a ubuntu 20.04 virtual machine with the same results).

solanav

solanav OP

I can’t get it to work, the extractor won’t start running until :msacc.start() has finished. Is this code alright?

def test do
  {:ok, file_data} = File.read("/home/solanav/krptkn/final_form.png")

  :msacc.start(2_000)
  Extractor.extract(file_data)
  :msacc.print()
  :msacc.stop
end

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews