java - Create a task that takes up a specific amount of CPU and RAM -


I am testing the software project of my company and want to see how it works in heavy load situations. . Is there any way to create a task that takes the CPU in large amounts and if I tell it, then only stops? If this program is not allowed, then what are the other options? As such software and input, can I get help with creating such a situation? thank you in advanced.

This program can be done by.

For Consumer CPU:

A simple dead loop will not consume all CPUs because your CPU has several logical cores, so you have to create There are multiple threads required to do this here:

  DWORD WINAPI ConsumeSingleCore (LPVOID lpThreadParameter) {DWORD_PTR mask = 1 & lt; & Lt; (Int) lpThreadParameter; :: SetThreadAffinityMask (:: GetCurrentThread (), Masks); For (;;) {}} Bad Consumption AllCores () {SYSTEM_INFO systemInfo = {0}; :: GetSystemInfo (& systemInfo); (DWORD i = 0; i & lt; systemInfo.dwNumberOfProcessors; ++ i) {:: CreateThread (Zero; 0, ConsumersLink, (LPVOD), 0, NULL); For storage:   

Allocating enough items on a heap will be helpful, although it is not very accurate, because there will be some heightened due to the internal structures in the system, such as the heap. If you want the correct number I think the use of virtual memory will be a good option directly. Here's the code:

  Dismiss ConsumeRAM () {SYSTEM_INFO systemInfo = {0}; :: GetSystemInfo (& systemInfo); DWORD memSize = 1024 * 1024 * 1024; Char * buffer = (four *) :: Virtual Alloco (Null, Memisize, MAMRSERVEV | MAMMAMIMIT, PNEERWRETE); // Touch All Pages, so the system will try to allocate physical memory for them. (DWORD memAddrOffset = 0; memAddrOffset & lt; memSize; memAddrOffset + = systemInfo.dwPageSize) {Buffer [memAddrOffset] = 0; } Return; }  

And if you need some tools for testing, then you can try to take certain core and consume it for certain memory.


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -