Árvore de páginas

Versões comparadas

Chave

  • Esta linha foi adicionada.
  • Esta linha foi removida.
  • A formatação mudou.
Comentário: Atualização do código MallocIO

A função malloc (memory allocation) aloca espaço para um bloco de bytes consecutivos na memória RAM do computador e devolve o endereço deste bloco. Esta é uma função da biblioteca padrão das linguagens C e C++.

O programa MallocIO utiliza esta função para mensurar a latência de alocação de um bloco de memória e da alocação em disco, retornando os respectivos tempos e informando a viabilidade para o Protheus, com os retornos Ótimo, Bom, Ruim e Péssimo.

Este programa foi desenvolvido pelo time de tecnologia, na linguagem C++, em virtude de diversos problemas em cenários de virtualização, onde a farm estava com configurações default ou com problemas de firmware, ou ainda cenários que não possuem boa performance.

Você pode realizar o download neste link.

Expandir
titleVerifique o código utilizado
Bloco de código
languagecpp
firstline1
titlemallocio.cpp
linenumberstrue
#include "pch.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <iostream>
#include <fstream>

using namespace std;
int main()
{
    void *var = 0;

    time_t timer;
    time_t timer2;
    struct tm y2k = { 0 };
    double seconds;
    string msgret;

    printf("TESTE 1\n");
    
void msg(int value, int message_type)
{
	switch (message_type)
	{
	case 0:
		printf("  __  __    _    _     _     ___   ____     ___ ___  \n");
		printf(" |  \\/  |  / \\  | |   | |   / _ \\ / ___|   |_ _/ _ \\ \n");
		printf(" | |\\/| | / _ \\ | |   | |  | | | | |   _____| | | | |\n");
		printf(" | |  | |/ ___ \\| |___| |__| |_| | |__|_____| | |_| |\n");
		printf(" |_|  |_/_/   \\_\\_____|_____\\___/ \\____|   |___\\___/ \n");
		printf("                                               xVs xArc\n");
		printf("                                                   \n");
		printf(" \n");
		break;
	case 1:
		printf(" \n");
		printf(" \n");
		printf("TESTE 1\n");
		printf("ALOCANDO BLOCO DE MEMORIA\n");
		printf(" \n");
		break;
	case 2:
		printf(" \n");
		printf(" \n");
		printf("TESTE 2\n");
		printf("ESCRITA EM DISCO\n");
		printf(" \n");
		break;
	case 3:
		printf(" \n");
		printf(" \n");
		printf("TESTE 3\n");
		printf("LEITURA EM DISCO\n");
		printf(" \n");
		break;
	default:
		break;
	}

}

int main()
{
	void *var = 0;

	time_t timer;
	time_t timer2;
	struct tm y2k = { 0 };
	double seconds;
	string msgret;

	msg(1,0);
	
	// ALOCANDO BLOCO DE MEMORIA
	msg(1,1);

	y2k.tm_hour = 0;   y2k.tm_min = 0; y2k.tm_sec = 0;
    	y2k.tm_year = 100; y2k.tm_mon = 0; y2k.tm_mday = 1;
    	timer = time(NULL);

    	for (int i = 0; i < 300000000; i++)
	{
		var = malloc(100);
		free(var);
	}

	timer2 = time(NULL);
	seconds = timer2 - timer;

	printf("TEMPO LEVADO PARA ALOCAR MEMORIA: %f segundos\n", seconds);
	printf(" \n");
	if (seconds <= 10) {
		printf("RESULTADO DO TESTE: Otimo -> RECOMENDADO PARA O PROTHEUS\n");
	}
	else if (seconds > 10 && varseconds <= malloc(100);
        free(var);
    }

    timer215) {
		printf("RESULTADO DO TESTE: Bom -> NAO recomendado para o Protheus\n");
	}
	else if (seconds > 15 && seconds <= 25) {
		printf("RESULTADO DO TESTE: Ruim -> NAO recomendado para o Protheus\n");
	}
	else {
		printf("RESULTADO DO TESTE: Pessimo -> NAO recomendado para o Protheus\n");
	}

	// ESCRITA EM DISCO
	msg(1,2);

	y2k.tm_hour = 0;   y2k.tm_min = 0; y2k.tm_sec = 0;
	y2k.tm_year = 100; y2k.tm_mon = 0; y2k.tm_mday = 1;
	timer = time(NULL);

	ofstream TesteFile("teste.txt");
	
	for (int i = 0; i < 7000000; i++){
		TesteFile << "Teste\n";
	}
	remove("teste.txt");

	timer2 = time(NULL);
	seconds = timer2 - timer;

    	printf("TEMPO LEVADO PARA ALOCAR MEMORIA REALIZAR A ESCRITA EM DISCO: %f segundos\n", seconds);

    	printf("TESTE 2\n");
	
	ofstream TesteFile1("teste.txt");
	for (int i = 0;  printf("LEITURA EM DISCOi < 10000; i++){
		TesteFile1 << "Teste\n");
	}

	// LEITURA   EM DISCO
	msg(1,3);

	y2k.tm_hour = 0;   y2k.tm_min = 0; y2k.tm_sec = 0;
    	y2k.tm_year = 100; y2k.tm_mon = 0; y2k.tm_mday = 1;
    	timer = time(NULL);

    	char * buffer;
    	FILE *pFile = fopen("teste.txt", "rb");
    	long lSize = ftell(pFile);
    	size_t result;
    	buffer = (char*)malloc(sizeof(char)*lSize);
    	for (int i = 0; i < 7000000; i++)
    	{
        		fseek(pFile, 0, SEEK_END);
        		result = fread(buffer, 1, lSize, pFile);
	}
	fclose(pFile);
	free(buffer);

	remove("teste.txt");

	timer2 = time(NULL);
	seconds = timer2 - }
    fclose(pFile);
    free(buffer);
    timer2 = time(NULL);
    seconds = timer2 - timer;

    printf("TEMPO LEVADO PARA REALIZAR A LEITURA EM DISCO: %f segundos\n", secondstimer;

	printf("TEMPO LEVADO PARA REALIZAR A LEITURA EM DISCO: %f segundos\n", seconds);
	printf(" \n");
	if (seconds <= 10) {
		printf("RESULTADO DO TESTE: Otimo -> RECOMENDADO PARA O PROTHEUS\n");
	}
	else if (seconds > 10 && seconds <= 25) {
		printf("RESULTADO DO TESTE: Bom -> NAO recomendado para o Protheus\n");
	}
	else if (seconds > 25 && seconds <= 26) {
		printf("RESULTADO DO TESTE: Ruim -> NAO recomendado para o Protheus\n");
	}
	else {
		printf("RESULTADO DO TESTE: Pessimo -> NAO recomendado para o Protheus\n");
	}

	printf(" \n");
	printf(" \n");
	printf(" ***********************************************************************\n");
	printf(" \n");
	printf(" TABELA DE REFERENCIA - ALOCAR BLOCO DE MEMORIA\n");
	printf(" \n");
	printf("Otimo   - ate 10.000000 segundos (RECOMENDADO PARA O PROTHEUS)\n");
	printf("Bom     - ate 15.000000 segundos (NAO recomendado para o Protheus)\n");
	printf("Ruim    - ate 25.000000 segundos (NAO recomendado para o Protheus)\n");
	printf("Pessimo -   + 25.000000 segundos (NAO recomendado para o Protheus)\n");
	printf(" \n");

	printf(" TABELA DE REFERENCIA - LEITURA EM DISCO\n");
	printf(" \n");
	printf("Otimo   - ate 10.000000 segundos (RECOMENDADO PARA O PROTHEUS)\n");
	printf("Bom     - ate 25.000000 segundos (NAO recomendado para o Protheus)\n");
	printf("Ruim    - ate 26.000000 segundos (NAO recomendado para o Protheus)\n");
	printf("Pessimo -   + 26.000000 segundos (NAO recomendado para o Protheus)\n");
	printf(" \n");
}
20

.

000000

Tempo de leitura do arquivo teste:

Expandir
titleUtlizando Utilizando o MallocIO

Em modo TEXTO (prompt de comando em Windows, ou modo shell em Linux), acesse o diretório do executável e execute o mesmo como Administrador em Windows ou root em Linux.

Aparecerá Executando em modo DOS, você terá a seguinte tela:

Image Added


ALOCANDO BLOCO DE MEMÓRIA

Representam Representa o momento de início da alocação e de final da alocação do bloco de memória. Como resposta, você receberá aparecerá o tempo de execução.

Tempo para alocar bloco de memória:

Até 10 segundos

Ótimo

Até 15 segundos

Bom

Até 25 segundos

Ruim

Acima de 25 segundos

Péssimo


LEITURA EM DISCO

Representam Representa o momento de início e final de leitura em de um arquivo .txt e o final da leitura. Verifique na tabela de referência se o seu resultado será adequado para o Protheus.

Tempo para alocar bloco de memória:

10.000000

até

Ótimo

21.000000

até

24.000000

Bom

25.000000

até

29.000000

Ruim

30.000000

até

40.000000

Péssimo

Até 10

.000000 seconds

segundos

Ótimo

25.000000 seconds

Até 25  segundos

Bom

Até 26

.000000 seconds

segundos

Ruim

40.000000 seconds

Acima de 26 segundos

Péssimo