Skip to content

Commit

Permalink
add batch sizes to logger
Browse files Browse the repository at this point in the history
Reviewed By: iamirzhan

Differential Revision: D66756347

fbshipit-source-id: f152addab017e7d2e800278d3fc297bcdd03c086
  • Loading branch information
Simon Marlow authored and facebook-github-bot committed Dec 9, 2024
1 parent 643241e commit 53aecb5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
20 changes: 19 additions & 1 deletion glean/db/Glean/Backend/Logging.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import Glean.Backend.Local ()
import Glean.Logger.Server as Logger
import qualified Glean.Database.List as Database
import qualified Glean.Database.Types as Database
import Glean.Database.Writes (batchOwnedSize, batchDependenciesSize)
import Glean.Logger
import qualified Glean.Types as Thrift
import Util.Time
Expand Down Expand Up @@ -142,7 +143,7 @@ instance Backend LoggingBackend where
deleteDatabase env repo
enqueueBatch (LoggingBackend env) cbatch =
loggingAction
(runLogRepo "enqueueBatch" env (Thrift.computedBatch_repo cbatch))
(runLogEnqueueBatch "enqueueBatch" env cbatch)
(const mempty) $
enqueueBatch env cbatch
enqueueJsonBatch (LoggingBackend env) repo batch =
Expand Down Expand Up @@ -233,6 +234,23 @@ runLogQueryBatch cmd env repo Thrift.UserQueryBatch{..} log =
, maybe mempty logQueryClientInfo userQueryBatch_client_info
]

runLogEnqueueBatch
:: Text
-> Database.Env
-> Thrift.ComputedBatch
-> GleanServerLog
-> IO ()
runLogEnqueueBatch cmd env Thrift.ComputedBatch{..} log =
let !Thrift.Batch{..} = computedBatch_batch in
runLogRepo cmd env computedBatch_repo $ mconcat
[ log
, Logger.SetBatchFactsSize $ ByteString.length batch_facts
, Logger.SetBatchFactsCount $ fromIntegral $
Thrift.batch_count computedBatch_batch
, Logger.SetBatchOwnedSize $ batchOwnedSize batch_owned
, Logger.SetBatchDependenciesSize $ batchDependenciesSize batch_dependencies
]

logQueryOptions :: Thrift.UserQueryOptions -> GleanServerLog
logQueryOptions Thrift.UserQueryOptions{..} = mconcat
[ Logger.SetNoBase64Binary userQueryOptions_no_base64_binary
Expand Down
17 changes: 14 additions & 3 deletions glean/db/Glean/Database/Writes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ module Glean.Database.Writes
, reapWrites
, writerThread
, deleteWriteQueues
, batchOwnedSize
, batchDependenciesSize
) where

import Control.Concurrent
Expand Down Expand Up @@ -307,15 +309,24 @@ enqueueBatch env ComputedBatch{..} ownership = do
batchSize :: Thrift.Batch -> Int
batchSize Thrift.Batch{..} =
ByteString.length batch_facts +
Monoid.getSum (foldMap (Monoid.Sum . storableSize) batch_owned) +
Monoid.getSum (foldMap (Monoid.Sum . depsSize) batch_dependencies)
batchOwnedSize batch_owned +
batchDependenciesSize batch_dependencies

batchOwnedSize :: HashMap UnitName ListOfIds -> Int
batchOwnedSize = Monoid.getSum . foldMap (Monoid.Sum . storableSize)

batchDependenciesSize :: HashMap Id [FactDependencies] -> Int
batchDependenciesSize deps =
Monoid.getSum (foldMap (Monoid.Sum . depsSize) deps)
where
storableSize = snd . VS.unsafeToForeignPtr0
depsSize deps = sum
[ storableSize f + storableSize d
| FactDependencies f d <- deps
]

storableSize :: VS.Storable a => VS.Vector a -> Int
storableSize = snd . VS.unsafeToForeignPtr0

enqueueJsonBatch
:: Env
-> Repo
Expand Down
4 changes: 4 additions & 0 deletions glean/db/Glean/Logger/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ data GleanServerLog
| SetRequestContinuationSize Int
| SetResponseContinuationSize Int
| SetSchemaId Text
| SetBatchFactsSize Int
| SetBatchFactsCount Int
| SetBatchOwnedSize Int
| SetBatchDependenciesSize Int

instance Semigroup GleanServerLog where
a <> b = GleanServerLogAnd a b
Expand Down

0 comments on commit 53aecb5

Please sign in to comment.