Skip to content

Commit

Permalink
introducing TRawAsyncServer.ComputeRandomWorld
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud Bouchez committed Apr 23, 2024
1 parent 6aad75f commit d312c00
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions ex/techempower-bench/raw.pas
Expand Up @@ -95,6 +95,7 @@ TRawAsyncServer = class(TSynPersistent)
fTemplate: TSynMustache;
fCachedWorldsTable: POrmCacheTable;
fRawCache: TOrmWorlds;
fRandom: TLecuyer;
{$ifdef USE_SQLITE3}
fDbPool: TSqlDBSQLite3ConnectionProperties;
procedure GenerateDB;
Expand All @@ -106,6 +107,7 @@ TRawAsyncServer = class(TSynPersistent)
// pipelined reading as used by /rawqueries and /rawupdates
function GetRawRandomWorlds(cnt: PtrInt; out res: TWorlds): boolean;
function ComputeRawFortunes(stmt: TSqlDBStatement; ctxt: THttpServerRequest): integer;
function ComputeRandomWorld: integer; inline;
public
constructor Create(threadCount: integer; flags: THttpServerOptions;
pin2Core: integer); reintroduce;
Expand Down Expand Up @@ -159,12 +161,6 @@ TRawAsyncServer = class(TSynPersistent)
'</body>' +
'</html>';


function ComputeRandomWorld: integer; inline;
begin
result := Random32(WORLD_COUNT) + 1;
end;

function GetQueriesParamValue(ctxt: THttpServerRequest;
const search: RawUtf8 = 'QUERIES='): cardinal; inline;
begin
Expand Down Expand Up @@ -208,6 +204,7 @@ constructor TRawAsyncServer.Create(
// setup the main ORM store
fStore := TRestServerDB.Create(fModel, SQLITE_MEMORY_DATABASE_NAME);
fStore.NoAjaxJson := true;
fRandom.Next;
{$ifdef USE_SQLITE3}
GenerateDB;
{$else}
Expand Down Expand Up @@ -255,6 +252,11 @@ destructor TRawAsyncServer.Destroy;
inherited Destroy;
end;

function TRawAsyncServer.ComputeRandomWorld: integer;
begin
result := ((QWord(fRandom.RawNext) * WORLD_COUNT) shr 32) + 1;
end;

{$ifdef USE_SQLITE3}

const
Expand Down
2 changes: 1 addition & 1 deletion src/mormot.commit.inc
@@ -1 +1 @@
'2.2.7378'
'2.2.7379'

0 comments on commit d312c00

Please sign in to comment.