来自:hfghfghfg, 时间:2004-2-5 8:19:00, ID:2436816 | 编辑
to qince;
我 认为 server 写 到 这样 就 可以 了。{考虑 到 还有 网络 上 的 瓶颈}
我 算 过, 一秒 中 产生 的 数据 有 一兆。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, Provider, DBClient, StdCtrls, Spin;
const
MaxRecordCount = 300;
type
TDoThread = class(TThread)
private
FDataSet: TDataSet;
FMemo: TMemo;
FDoCount: integer;
FFilter: string;
FMemoName: string;
procedure getData;
protected
procedure Execute;
override;
public
constructor Create(DataSet: TDataSet;
DoCount: Integer;
m: TMemo;
MemoName: string);
end;
type
TForm1 = class(TForm)
ADODataSet1: TADODataSet;
ClientDataSet1: TClientDataSet;
DataSetProvider1: TDataSetProvider;
Button1: TButton;
GroupBox1: TGroupBox;
Memo1: TMemo;
GroupBox2: TGroupBox;
Memo2: TMemo;
Button2: TButton;
SpinEdit1: TSpinEdit;
SpinEdit2: TSpinEdit;
Label1: TLabel;
Label2: TLabel;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TDoThread }
constructor TDoThread.Create(DataSet: TDataSet;
DoCount: Integer;
m: TMemo;
MemoName: string);
begin
FDataSet := DataSet;
FMemo := m;
FMemoName := MemoName;
FDoCount :=do
Count;
FreeOnTerminate := True;
inherited Create(False);
Priority := tpLower;
end;
procedure TDoThread.Execute;
var
i: integer;
begin
for i := 1 to FDoCountdo
begin
FFilter := 'F1 <> ''999'' ';
Synchronize(GetData);
end;
end;
procedure TDoThread.getData;
var
ss: TMemoryStream;
strData, SendData: string;
nowCount, i, j: integer;
begin
//
nowCount := random(MaxRecordCount);
FDataSet.First;
ss := TMemoryStream.Create;
try
FDataSet.Filter := FFilter;
FDataSet.Filtered := true;
with FDataSetdo
begin
for i := 1 to nowCountdo
if eof then
break
else
begin
for j := 0 to 9do
begin
strData := Fields[j].AsString;
ss.Write(strData[1], length(strData));
end;
next;
end;
end;
except
;
end;
setlength(SendData, ss.size);
ss.Read(SendData[1], ss.Size);
if Fmemo.Lines.Count > 10000 then
Fmemo.Lines.Clear;
Fmemo.Lines.Add(format('%s 线称%s: 记录数%d length(SendData)%d', [formatdatetime('hh:nn:ss', now), FMemoName, nowCount, length(SendData)]));
freeandnil(ss);
SendData := '';
strData := '';
Application.ProcessMessages;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i: integer;
begin
Randomize;
for i := 1 to 10do
ADODataSet1.FieldDefs.Add('F' + inttostr(i), ftstring, 50);
ADODataSet1.CreateDataSet;
ADODataSet1.Open;
for i := 1 to 10000do
ADODataSet1.AppendRecord([i, 'aaaaaaaaaaaaaaaaaaaaaa', 'aaaaaaaaaaaaaaaaaaaaaa', 'aaaaaaaaaaaaaaaaaaaaaa', 'aaaaaaaaaaaaaaaaaaaaaa', 'aaaaaaaaaaaaaaaaaaaaaa', 'aaaaaaaaaaaaaaaaaaaaaa', 'aaaaaaaaaaaaaaaaaaaaaa', 'aaaaaaaaaaaaaaaaaaaaaa', 'aaaaaaaaaaaaaaaa']);
ADODataSet1.First;
ClientDataSet1.Open;
// ADODataSet1.Close;
// showmessage(inttostr(ClientDataSet1.RecordCount));
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
begin
for i := 1 to SpinEdit1.Valuedo
begin
TDoThread.Create(ClientDataSet1, { random(10000) +} SpinEdit2.Value, memo1, inttostr(i));
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
i: integer;
begin
for i := 1 to SpinEdit1.Valuedo
begin
TDoThread.Create(ADODataSet1, { random(10000) +} SpinEdit2.Value, memo2, inttostr(i));
end;
end;
end.
object Form1: TForm1
Left = 99
Top = 210
BorderStyle = bsSingle
Caption = 'Form1'
ClientHeight = 453
ClientWidth = 816
Color = clBtnFace
Font.Charset = GB2312_CHARSET
Font.Color = clWindowText
Font.Height = -12
Font.Name = '宋体'
Font.Style = []
OldCreateOrder = False
Position = poScreenCenter
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 12
object Label1: TLabel
Left = 351
Top = 8
Width = 36
Height = 12
Caption = '线称数'
end
object Label2: TLabel
Left = 351
Top = 136
Width = 96
Height = 12
Caption = '每个线称的工作量'
end
object Button1: TButton
Left = 375
Top = 216
Width = 75
Height = 25
Caption = 'c'
TabOrder = 0
OnClick = Button1Click
end
object GroupBox1: TGroupBox
Left = 0
Top = 0
Width = 340
Height = 453
Align = alLeft
Caption = 'ClientDataSet1'
TabOrder = 1
object Memo1: TMemo
Left = 2
Top = 14
Width = 336
Height = 437
Align = alClient
TabOrder = 0
end
end
object GroupBox2: TGroupBox
Left = 476
Top = 0
Width = 340
Height = 453
Align = alRight
Caption = 'ADODataSet1'
TabOrder = 2
object Memo2: TMemo
Left = 2
Top = 14
Width = 336
Height = 437
Align = alClient
TabOrder = 0
end
end
object Button2: TButton
Left = 375
Top = 272
Width = 75
Height = 25
Caption = 'A'
TabOrder = 3
OnClick = Button2Click
end
object SpinEdit1: TSpinEdit
Left = 351
Top = 24
Width = 121
Height = 21
MaxValue = 0
MinValue = 0
TabOrder = 4
Value = 100
end
object SpinEdit2: TSpinEdit
Left = 351
Top = 152
Width = 121
Height = 21
MaxValue = 0
MinValue = 0
TabOrder = 5
Value = 100
end
object ADODataSet1: TADODataSet
Parameters = <>
Left = 472
Top = 56
end
object ClientDataSet1: TClientDataSet
Aggregates = <>
Params = <>
ProviderName = 'DataSetProvider1'
ReadOnly = True
Left = 480
Top = 184
end
object DataSetProvider1: TDataSetProvider
DataSet = ADODataSet1
Constraints = True
Left = 480
Top = 112
end
end
来自:hfghfghfg, 时间:2004-2-5 8:24:00,