PAGUE 6 MESES
LEVE 12 MESES
GARANTIR DESCONTO

Fórum Desempenho das aplicações DataSnap e Cliente Servidor #452239

16/08/2013

0

Desempenho das aplicações DataSnap e Cliente Servidor

Os teste foram realizados com apenas uma estação de trabalho, tanto para o dataSnap quanto para o cliente servidor.

A idéia deste teste foi apenas para fazer análise de desempenho do datasnap comparado com o cliente servidor! Caso alguém conheça
maneiras de otimizar o servidor datasnap, agradeço.

Estou a entender que o DataSnap está lento, mas como não sou um especialista do assunto estou aberto a sugestões!



Resultados .:

DataSnap Processando... | Cliente Servidor Processando...
Total Registros .: 1000 | Total Registros .: 1000
Tempo Inicial .: 17:29:55:240 | Tempo Inicial .: 17:37:53:873
Tempo Final .: 17:30:01:826 | Tempo Final .: 17:37:54:814
Tempo Total .: 00:00:06:586 | Tempo Total .: 00:00:00:941
------------------------------------------------------------------------------------
DataSnap Processando... | Cliente Servidor Processando...
Total Registros .: 3000 | Total Registros .: 3000
Tempo Inicial .: 17:30:08:127 | Tempo Inicial .: 17:37:59:257
Tempo Final .: 17:30:27:118 | Tempo Final .: 17:38:04:102
Tempo Total .: 00:00:18:991 | Tempo Total .: 00:00:04:845
------------------------------------------------------------------------------------
DataSnap Processando... | Cliente Servidor Processando...
Total Registros .: 5000 | Total Registros .: 5000
Tempo Inicial .: 17:30:32:69 | Tempo Inicial .: 17:38:08:992
Tempo Final .: 17:31:02:776 | Tempo Final .: 17:38:18:75
Tempo Total .: 00:00:30:707 | Tempo Total .: 00:00:09:83
------------------------------------------------------------------------------------
DataSnap Processando... | Cliente Servidor Processando...
Total Registros .: 7000 | Total Registros .: 7000
Tempo Inicial .: 17:31:07:811 | Tempo Inicial .: 17:38:22:983
Tempo Final .: 17:31:50:998 | Tempo Final .: 17:38:29:800
Tempo Total .: 00:00:43:187 | Tempo Total .: 00:00:06:817
------------------------------------------------------------------------------------
DataSnap Processando... | Cliente Servidor Processando...
Total Registros .: 10000 | Total Registros .: 10000
Tempo Inicial .: 17:31:56:328 | Tempo Inicial .: 17:38:38:934
Tempo Final .: 17:32:58:168 | Tempo Final .: 17:38:56:623
Tempo Total .: 00:01:01:840 | Tempo Total .: 00:00:17:689
------------------------------------------------------------------------------------




Veja Abaixo a Estrutura das aplicações, adicionado somente os itens principais.


Estrutura do DataSnap

-- [ Servidor ]
contém 3 units: { UnitPrincipal, ServerMethods, ServerContainer }

--> Formulário Principal
Apenas o próprio formulario.:

-> ServerMethods:
Componentes
TDBXConnection { Driver = ASA ; KeepConnection = True ; Name = ConnectionBD}
TSqlQuery { SQLConnection = ConnectionBD ; Name = fSqlQuery}
Métodos contidos nesta Unit:
[url] http://uploaddeimagens.com.br/images/000/069/244/original/ServerMethods.jpg?1376689844 [/url]

			procedure RegistrarDados(const fObjectJson: TJSONValue);
			procedure RegistrarDadosArray(const fArrayJson: TJSONArray);


-> ServerContainer:
[url] http://uploaddeimagens.com.br/images/000/069/245/original/ServerContainer.jpg?1376689893 [/url]

Componentes
DSServer1 { AutoStart = True; ChannelQueueSize = 100; ChannelResponseTimeout = 30000}
DSTCPServerTransport1 { BufferKbSize = 32; KeepAliveEnablement = kaEnabled; KeepAliveInterval = 100; KeepAliveTime: 300000; MaxThreads = 100; PoolSize = 10; Port = 200}
DSServerClass1 { LiveCycle = session}

Implementação dos métodos da unit ServerMethods;

	procedure TServerMethods.RegistrarDados(const fObjectJson: TJSONValue);
       		var fDados:TInsertDados;
	begin
   	      try
      		fDados := (JsonToClass(fObjectJson) as TInsertDados);
      		with fSqlQuery do
      		begin
         			close;
         			sql.clear;
         			sql.Add('INSERT INTO TBTESTE (CODIGO,DESCRICAO) VALUES (:CODIGO,:DESCRICAO)');
         			parambyname('CODIGO').AsInteger       := fDados.codigo;
         			parambyname('DESCRICAO').AsString  := fDados.nome;
         			ExecSQL();
      		end;
   	     finally
      		FreeAndNil(fDados);
	     end;
	end;


	procedure TServerMethods.RegistrarDadosArray(const fArrayJson: TJSONArray);
	var I: Integer;
                     fDados:TInsertDados;
	begin
   		with fSqlQuery do
   		begin
      			close;
      			sql.clear;
      			sql.Add('INSERT INTO TBTESTE (CODIGO,DESCRICAO) VALUES (:CODIGO,:DESCRICAO)');
      			for I := 0 to fArrayJson.Size-1 do
     	 		begin
         				try
            					fDados                                                   :=  (JsonToClass(fArrayJson.Get(I)) as TVODados);
            					parambyname('CODIGO').AsInteger       :=  fDados.codigo;
            					parambyname('DESCRICAO').AsString  :=  fDados.nome;
            					ExecSQL();
         				finally
            					FreeAndNil(fDados);
         				end;
      			end;
   		end;
	end;


-- [ Cliente ]
contém 3 units: { UnitPrincipal, DmGeral, UnitMetodosRemotos }

-> DmGeral:
Componentes :
TDBXConnection {name = SQLConnectionSVR ; Driver = DataSnap; CommunicationProtocol = TCP/IP; HostName = 192.168.1.157; Port = 200; KeepConnection = True}
-> Formulário Principal
[url] http://uploaddeimagens.com.br/images/000/069/257/original/Cliente_Principal.jpg?1376691234 [/url]
Código do botão [ Registrar ]

		procedure TFormPrincipal_CLient.Button1Click(Sender: TObject);
			var fDados     : TInsertDados;
       			fMetodos   : TServerMethods1Client;
       			I, nQtde    : Integer;
       			fJsonA     : TJSONArray;
       			fTempoIni,fTtempofim:TDateTime;
		begin
   		     try
      			fMetodos   := TServerMethods1Client.Create(DmGeral.SQLConnectionSVR.DBXConnection);
      			nQtde        := StrToInt(EditNQtdeInsercao.Text);
      			fTempoIni  := now;
      			case RadioGroupProcessar.ItemIndex of
         			      0:begin
              				lblTIni.Caption := FormatDateTime('HH:MM:SS:Z',fTempoIni);
              				Memo1.Lines.Add('Cliente Processando...');
              				for I := 0 to nQtde do
              				begin
                 				fDados             := TInsertDados.Create;
                 				fDados.codigo   := I;
                 				fDados.nome    := 'Teste'+IntToStr(I);
                 				fNegocio.GravarDados(fDados);
                 				FreeAndNil(fDados);
              				end;
         			     end;
         			     1:begin
              				lblTIni.Caption := FormatDateTime('HH:MM:SS:Z',fTempoIni);
              				Memo1.Lines.Add('Servidor Processando...');
              				fJsonA            := TJSONArray.Create;
              				for I := 0 to nQtde do
              				begin
                 				fDados               := TInsertDados.Create;
                 				fDados.codigo     := I;
                 				fDados.nome      := 'Teste'+IntToStr(I);
                 				fJsonA.AddElement(ClassToJSON(fDados));
                 				FreeAndNil(fDados);
              				end;
              				fMetodos.GravarDadosArray(fJsonA);
         			      end;
      			end;
      			tTtempofim          := now;
      			lblTFim.Caption    := FormatDateTime('HH:MM:SS:Z',fTtempofim);
      			lblTotal.Caption     := FormatDateTime('HH:MM:SS:Z',fTtempofim-fTempoIni);
      			Memo1.Lines.Add('Total Registros .: '+EditNQtdeInsercao.Text);
      			Memo1.Lines.Add('Tempo Inicial   .: '+lblTIni.Caption);
      			Memo1.Lines.Add('Tempo Final     .: '+lblTFim.Caption);
      			Memo1.Lines.Add('Tempo Total     .: '+lblTotal.Caption);
      			Memo1.Lines.Add('-------------- ');
      			Application.ProcessMessages;
      			MessageDlg('Registros Inserido com Sucesso',mtInformation,[mbOk],0);
   		   finally
      			FreeAndNil(fMetodos);
   		   end;
	             end;


-- [ Funções Gerais ]

	function ClassToJSON(NomeClasse: TObject):TJSONValue;
   	function JsonToClass(Json: TJSONValue):TObject;


Implementação das Funções

	function ClassToJSON(NomeClasse: TObject):TJSONValue;
  		var mar: TJSONMarshal;
	begin
   		if Assigned(NomeClasse) then
   		begin
     	 		mar := TJSONMarshal.Create(TJSONConverter.Create);
      			try
         				exit(mar.Marshal(NomeClasse));
      			finally
         				mar.Free;
      			end;
   		end
   		else
      			exit(TJSONNull.Create);
	end;

	function JsonToClass(Json: TJSONValue):TObject;
  		var unm: TJSONUnMarshal;
	begin
    		if json is TJSONNull then
      			exit(nil);
    		unm := TJSONUnMarshal.Create;
    		try
      			exit(unm.Unmarshal(Json) as TObject);
    		finally
      			unm.Free;
    		end;
	end;


-- [ Classe VO ]

   TInsertDados = Class
      private
          Fcodigo: integer;
          Fnome: String;
          procedure Setcodigo(const Value: integer);
          procedure Setnome(const Value: String);
      public
          property codigo:integer read Fcodigo write Setcodigo;
          property nome:String read Fnome write Setnome;
   End;


Implementação da Classe .:

	procedure TInsertDados.Setcodigo(const Value: integer);
	begin
  		Fcodigo := Value;
	end;

	procedure TInsertDados.Setnome(const Value: String);
	begin
  		Fnome := Value;
	end;


----------------------------------------------------------------------------------------------

Implementação do Cliente Servidor
contém 3 units: { UnitPrincipal, DmGeral, UnitGerarDados}

--> DmGeral
componentes: TDBXConnection { Driver = ASA ; KeepConnection = True ; Name = ConnectionBD}
TSqlQuery { SQLConnection = ConnectionBD ; Name = fSqlQuery}

métodos:
function TDmGeral.GravarRegistros(const fDados: TInsertDados): boolean;

Implementação do método
			function TClientModule1.GravarRegistros(const fDados: TInsertDados): boolean;
			begin
   				try
     	 				with fSqlQuery do
      					begin
         						close;
         						sql.clear;
         						sql.Add('INSERT INTO TBTESTE (CODIGO,DESCRICAO) VALUES (:CODIGO,:DESCRICAO)');
         						parambyname('CODIGO').AsInteger      := fDados.codigo;
         						parambyname('DESCRICAO').AsString  := fDados.nome;
         						ExecSQL();
      					end;
   				finally
      					//
   				end;
			end;


--> UnitGerarDados

      		TGerarDados = class
         		public
            			procedure GerarDados(const qtde:integer);
      		end;


Implementação do método
//------------------------ Não foram feitos nenhuma validação por que não é o objetivo
			function TGerarDados.GerarDados(const qtde:integer): boolean;
				var I: Integer;
				vInsertDados: TInsertDados
			begin
      				for I := 0 to qtde do
      				begin
					try
         						vInsertDados            := TInsertDados.Create;
						vInsertDados.codigo  := I;
         						vInsertDados.nome   := 'Teste'+IntToStr(I);
         						ClientModule.ClientModule1.GravarRegistros(vInsertDados);
					finally
						FreeAndNil(vInsertDados);
					end;
      				end;
   			end;


--> UnitPrincipal
Código do botão [ Registrar ]

		procedure TFormPrincipal_CLient.Button1Click(Sender: TObject);
  	 		var fTempoIni,fTtempofim:TDateTime;
       			      fGerarDados:TGerarDados;
		begin
   			try
      				fTempoIni         := now;
                 			lblTIni.Caption := FormatDateTime('HH:MM:SS:Z',fTempoIni);
              				Memo1.Lines.Add('Cliente Servidor Processando...');

      				fGerarDados := TGerarDados.Create;
				fGerarDados.GerarDados(StrToInt(EditNQtdeInsercao.Text));

      				fTtempofim         := now;
      				lblTFim.Caption   := FormatDateTime('HH:MM:SS:Z',fTtempofim);
      				lblTotal.Caption   := FormatDateTime('HH:MM:SS:Z',fTtempofim-fTempoIni);
      				Memo1.Lines.Add('Total Registros .: '+EditNQtdeInsercao.Text);
      				Memo1.Lines.Add('Tempo Inicial   .: '+lblTIni.Caption);
      				Memo1.Lines.Add('Tempo Final     .: '+lblTFim.Caption);
      				Memo1.Lines.Add('Tempo Total     .: '+lblTotal.Caption);
      				Memo1.Lines.Add('-------------- ');
      				Application.ProcessMessages;
      				MessageDlg('Registros Inserido com Sucesso',mtInformation,[mbOk],0);
   			finally
      				FreeAndNil(fGerarDados);
   			end;
		end;

Hudson Leite

Hudson Leite

Responder

Posts

21/08/2013

Hudson Leite

Alguma Sugestão?
Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar