1

Topic: How to write the code consuming about 10 % of the processor?

Task statement the following: I have a code which in a cycle considers an arithmetical progression from 1 to n. Naturally this code consumes entirely one kernel, that is 100 % CPU. Also fulfills, we admit for a day. And me in general arranges, if the result is in 10 days, let the code works as a background easy and does not hinder to be played the computer. For this purpose it is necessary to tell somehow to the code that it worked more slowly. But how? On idea it is a question to those who did an operating system, probably in everyone there are any plugins for such pieces, but such probably it is possible to make and . A flow which more slowly the core for certain can be created? Meanwhile the cleverest that I invented - to do sleep. But it can is possible somehow on another? UPD. The code is written by me. I can edit and collect it anew. Restrictions that it is possible to work only with  - is not present.

2

Re: How to write the code consuming about 10 % of the processor?

For linux is  is called cpulimit (is in a standard repository), it is possible to try it, it restricts consumption of a resource by process and it is possible to set percent from 1 to 100

3

Re: How to write the code consuming about 10 % of the processor?

Hello, Terix, you wrote: T> Meanwhile the cleverest that I invented - to do sleep. But it can is possible somehow on another? About  to you already answered, and in Windows exist Job Objects, and Richter in the known book with them has example JobLab.

4

Re: How to write the code consuming about 10 % of the processor?

Hello, Glory, you wrote: About  to you already answered, and in Windows exist Job Objects, and Richter in the known book with them has example JobLab. And platform means only sleep?

5

Re: How to write the code consuming about 10 % of the processor?

It is called a process priority. In  it is possible it is direct in the manager of tasks to expose.

6

Re: How to write the code consuming about 10 % of the processor?

Hello, vsb, you wrote: vsb> It is called a process priority. In  it is possible it is direct in the manager of tasks to expose. The manager it is finite the decision, but it is interesting how generally to write the code which it is lazy and slowly something calculates hindering to nobody.

7

Re: How to write the code consuming about 10 % of the processor?

T> the Manager it is finite the decision, but it is interesting how generally to write the code which it is lazy and slowly something calculates hindering to nobody. It is possible to expose still a priority at Thread directly on the minimum

8

Re: How to write the code consuming about 10 % of the processor?

Hello, Terix, you wrote:> About  to you already answered, and in Windows exist Job Objects, and Richter in the known book with them has example JobLab. T> And platform means only sleep? Means of a platform to you even sleep does not help, because it it is necessary still . If you want to reach accuracy in 10 % of loading.

9

Re: How to write the code consuming about 10 % of the processor?

Hello, vsb, you wrote: vsb> It is called a process priority. In  it is possible it is direct in the manager of tasks to expose. Process with the lowest priority all the same consumes 100 % of the processor in the absence of other loading, also it creates the processor heating, the raised consumption of energy and noise from fans.

10

Re: How to write the code consuming about 10 % of the processor?

Hello, raydac, you wrote: T>> the Manager it is finite the decision, but it is interesting how generally to write the code which it is lazy and slowly something calculates hindering to nobody. R> it is possible to expose still a priority at Thread directly on minimum it would Seem yes, but upon setPriority it is not enough on what influences.

11

Re: How to write the code consuming about 10 % of the processor?

Hello, Glory, you wrote: Means of a platform to you even sleep does not help, because it it is necessary still . If you want to reach accuracy in 10 % of loading. I too thought of it, but, probably it is better so, than in any way. Accuracy actually is not necessary, it is necessary that the code did not load the processor. Application on JavaFX launched after all almost does not eat anything if there not to do anything. Though there on idea , check of signals from  and so on.

12

Re: How to write the code consuming about 10 % of the processor?

Hello, Terix, you wrote: vsb>> It is called a process priority. In  it is possible it is direct in the manager of tasks to expose. T> the manager it is finite the decision, but it is interesting how generally to write the code which it is lazy and slowly something calculates hindering to nobody. Nobody is hindered only by the sleeping code. As soon as the code wakes up to work, it can prevent someone. Who to whom can hinder - the scheduler of an operating system and the user on it defines can influence priorities of processes, defining, what process is important, and what not so. And intentionally to sleep 90 % of time of sense 0.

13

Re: How to write the code consuming about 10 % of the processor?

Hello, Glory, you wrote: vsb>> It is called a process priority. In  it is possible it is direct in the manager of tasks to expose. Process with the lowest priority all the same consumes 100 % of the processor in the absence of other loading Well so it well. The processor then also bought, that it quickly worked.> also it creates heating of the processor It is not a problem.> Totally the variant with hibernation consumes the raised consumption of energy more.> and noise from fans. It is necessary to select components correctly.

14

Re: How to write the code consuming about 10 % of the processor?

Hello, Terix, you wrote: T> I have a code which in a cycle considers an arithmetical progression from 1 to n. Naturally this code consumes entirely one kernel, that is 100 % CPU. Also fulfills, we admit for a day. And me in general arranges, if the result is in 10 days, let the code works as a background easy and does not hinder to be played the computer. For this purpose it is necessary to tell somehow to the code that it worked more slowly. But how? It would be more reasonable, that such process worked with a priority more low, than for "normal" processes. Then while the computer stands idle, he would consider the arithmetical progression and when the computer is occupied by something it would not be hindered. Only do not ask me as it to make in Java

15

Re: How to write the code consuming about 10 % of the processor?

Hello, Pzz, you wrote: Pzz> Only do not ask me as it to make in Java Thread.currentThread ().setPriority (Thread. MAX_PRIORITY);

16

Re: How to write the code consuming about 10 % of the processor?

Hello, GarryIV, you wrote: Pzz>> Only do not ask me as it to make in Java GIV> GIV> Thread.currentThread ().setPriority (Thread. MAX_PRIORITY); GIV> is faster MIN, instead of MAX And it precisely puts a priority of a flow of an operating system, instead of  the scheduler?

17

Re: How to write the code consuming about 10 % of the processor?

Hello, Terix, you wrote: T> Meanwhile the cleverest that I invented - to do sleep. But it can is possible somehow on another? Pulse-width modulation Th1: work work work... Th2: while (working) {sleep (tau1); Th1.pause (); sleep (tau2); Th1.resume ();} tau1 / (tau1+tau2) = 10 %

18

Re: How to write the code consuming about 10 % of the processor?

Hello, vsb, you wrote: vsb> Well so it is good. The processor then also bought, that it quickly worked. On a statement of the problem at us it is necessary, that it worked quickly, but to the program devoted only percent 10 - 20 times.

19

Re: How to write the code consuming about 10 % of the processor?

T> And me in general arranges, if the result is in 10 days, let the code works as a background easy and does not hinder to be played the computer. For this purpose it is necessary to tell somehow to the code that it worked more slowly. But how? Not more slowly, and with more low priority. That did not hinder to be played.

20

Re: How to write the code consuming about 10 % of the processor?

Hello, Pzz, you wrote: Pzz>>> Only do not ask me as it to make in Java GIV>> GIV>> Thread.currentThread ().setPriority (Thread. MAX_PRIORITY); GIV>> Pzz> is faster MIN, instead of MAX the Constant what  use. Pzz> and it precisely puts a priority of a flow of an operating system, instead of  the scheduler? Is not present any " the scheduler"

21

Re: How to write the code consuming about 10 % of the processor?

Hello, Terix, you wrote: vsb>> Well so it is good. The processor then also bought, that it quickly worked. T> on a statement of the problem at us it is necessary, that it worked quickly, but to the program devoted only percent 10 - 20 times. It is necessary to read not that invented asking, and what he wants to achieve. The person should count something, thus that this calculation did not hinder other programs. The correct method of it to achieve - to expose the under priority to calculation process. The wrong method - to try  the scheduler the methods, and it is wrong (process which wakes up for a second of times in 10 seconds, most likely will be unexpected  , for example). And correctly also it is impossible - is not present at process of such data to wake up "when it is necessary".

22

Re: How to write the code consuming about 10 % of the processor?

Hello, vsb, you wrote: vsb> It is necessary to read not that invented asking, and what he wants to achieve. Yes you see as, I and asked. And to achieve I wanted a method to make so that the program worked slowly in itself. It looks strange because I intentionally simplified the description. Generally imagine that we have a cycle shorthanding to the physicist. It also shorthands the world of 400 times in a second. Also loads percents on 100 % and for simulation to us and 40 times a second suffices. If simply to pass cycles entrance in while all the same  system on 100 %, and it not that that is necessary for us. Would Remain sleep like.

23

Re: How to write the code consuming about 10 % of the processor?

Hello, SkyDance, you wrote: SD> Not more slowly, and with more low priority. That did not hinder to be played. No, more slowly. It is possible to consider that we will have 2 flows. One slow, and another - normal.

24

Re: How to write the code consuming about 10 % of the processor?

T> the Manager it is finite the decision, but it is interesting how generally to write the code which it is lazy and slowly something calculates hindering to nobody. You are engaged in nonsense, a companion (or not up to the end wrote that actually is necessary for you). On performance the scheduler of OS is engaged in setting of tasks and for priority control of tasks there are standard tools of OS (in Linux is except priorities of processes which influence only a priority, but it is not so floppy, is also that is necessary for you - cgroups, allowing to arrange a ratio of time CPU between processes and groups of processes). But to do it it is necessary at operating system level. Because, if the computer sleeps, it is not necessary for you, that the program received only 10 % CPU, it should receive all resources. sleep () here not the decision - and a crutch (the program will work when wakes up, receiving resources CPU with a normal priority or even hardly big, since It only , and then completely ceases to receive resources, .. Creates periodic impulse loading instead of allowing the scheduler of processes to solve, when to the program to select CPU). Everything that the program in that case can make is somehow to inform OS that she wants only 10 % CPU. But what to do, if at the user or the system administrator other judgement, how many resources to give to the program? My judgement - such tasks is solved by OS, and was specific the scheduler of processes, it needs to be adjusted. And it is exact, not the program should adjust the scheduler.

25

Re: How to write the code consuming about 10 % of the processor?

T> Generally imagine that we have a cycle shorthanding to the physicist. It also shorthands the world of 400 times in a second. Also loads percents on 100 % and for simulation to us and 40 times a second suffices. If simply to pass cycles entrance in while all the same  system on 100 %, and it not that that is necessary for us. Would Remain sleep like. At last you wrote, in what the task actually consists. In such situation I would make, that the calculation flow fell asleep after each frame and he was awoken on the timer with other flow. Probably, it makes sense to calculate for some frames forward with a store, and also not to fall asleep, if frame calculation occupied too much time and it is time to calculate the following. Also it is possible to awake a flow at exhaustion of the calculated frames (or reduction below a minimum threshold). Schedulers, priorities and sleep () here generally at anything.