Code Monkey home page Code Monkey logo

Comments (3)

zugolosian avatar zugolosian commented on September 28, 2024 1

Got it working OK by splitting it into 16 chunks. For anyone that's interested in future here's some code to roughly split the log file by session ID.

#!/usr/bin/env python3
import hashlib
import argparse
import sys
import os
import csv

CSV_FIELDS = ['log_time', 'user_name', 'database_name', 'process_id', 'connection_from', 'session_id',
  'session_line_num', 'command_tag', 'session_start_time', 'virtual_transaction_id',
  'transaction_id', 'error_severity', 'sql_state_code', 'message', 'detail', 'hint', 'internal_query', 'internal_query_pos',
  'context', 'query', 'query_pos', 'location', 'application_name']
CSV_IDS = { CSV_FIELDS[i] : i for i in range(0, len(CSV_FIELDS) ) }

def main():

    parser = argparse.ArgumentParser(description='Split postgres csv log file into roughly equal chunks by session id')
    parser.add_argument('--log-file', type=str, help='The log file to parse')
    parser.add_argument('--split-count', type=int, help='Number to split the log file into')

    args = parser.parse_args()
    buckets = [[] for i in range(args.split_count)]
    csv.field_size_limit(sys.maxsize)
    with open(args.log_file, 'r') as csvfile:
        reader = csv.reader(csvfile)
        for row in reader:
            try:
                bucket_number = int(hashlib.sha256(row[CSV_IDS['session_id']].encode('utf-8')).hexdigest(), 16) % args.split_count
                buckets[bucket_number].append(row)
            except IndexError:
                print("index error encountered for row:{}".format(row))
                continue
    for index in range(args.split_count):
        split_file_name = 'split_file_{}_{}'.format(index, os.path.basename(args.log_file))
        with open(split_file_name, mode='w', encoding='utf-8') as split_file:
            writer = csv.writer(split_file, quoting=csv.QUOTE_MINIMAL)
            for row in buckets[index]:
                writer.writerow(row)

if __name__ == '__main__':
    try:
        main()
    except KeyboardInterrupt:
        print('Interrupted')
        try:
            sys.exit(0)
        except SystemExit:
            os._exit(0)

from pgreplay.

laurenz avatar laurenz commented on September 28, 2024

That's a fundamental limitation of pgreplay because of its single-threaded architecture.

At a certain load pgreplay will not be able to handle just sending queries and receiving the results and fall behind.

If you can split your log, that will work to some extent.
What you will lose is that pgreplay replays the statements in the same order in which they were originally.
If several pgreplay processes run against the same database, one can fall behind, while the other doesn't, and that man change the workload significantly if the statements in different sessions depend on each other.

I'd say that it splitting the log file should work good enough if all you need is an approximation of the actual workload.

from pgreplay.

laurenz avatar laurenz commented on September 28, 2024

Thanks for the feedback and the script!
I'll close the issue.

from pgreplay.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.