[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

High memory usage when using svn_fs_make_file()

From: Lars Jessen <LJessen_at_mikrov.dk>
Date: Mon, 21 Jan 2008 13:03:56 +0100

Hi,

I'm trying to use the the svn_fs module to build a database of 10000
files, but it seems that every call to svn_fs_make_file() eats about
300+kb of memory. The
following code illustrates the problem:

#include <apr_lib.h>
#include <svn_cmdline.h>
#include <svn_fs.h>
#include <svn_pools.h>
#include <iostream>
#include <strstream>

void CheckError(svn_error_t* error){
    if(error == NULL)
        return;
    std::cerr << "Error: " << error->message << std::endl;
    exit(-1);
}

int main(){
    const char* repositoryPath = "d:/svntest";

    svn_cmdline_init("svntest", stderr);

    apr_allocator_t *allocator;
    apr_allocator_create(&allocator);
    apr_allocator_max_free_set(allocator,
SVN_ALLOCATOR_RECOMMENDED_MAX_FREE);

    apr_pool_t *pool = svn_pool_create_ex(NULL, allocator);
    apr_allocator_owner_set(allocator, pool);
    if(NULL == pool){
        std::cerr << "Error initializing pool" << std::endl;
        return -1;
    }

    svn_error_t* error;

    error = svn_fs_initialize(pool);
    CheckError(error);

    svn_fs_t* fs;

    error = svn_fs_open(&fs, repositoryPath, NULL, pool);
    if(error){
        apr_hash_t* hash = apr_hash_make(pool);
        apr_hash_set(hash, SVN_FS_CONFIG_FS_TYPE, APR_HASH_KEY_STRING,
SVN_FS_TYPE_BDB);

        error = svn_fs_create(&fs, repositoryPath, NULL, pool);
        CheckError(error);
    }

    // Get revision
    svn_revnum_t youngest_rev;
    error = svn_fs_youngest_rev(&youngest_rev, fs, pool);
    CheckError(error);

    svn_fs_txn_t *txn;

    apr_pool_t *txpool = svn_pool_create_ex(pool, allocator);

    error = svn_fs_begin_txn(&txn, fs, youngest_rev, txpool);
    CheckError(error);

    svn_fs_root_t* root;
    error = svn_fs_txn_root(&root, txn, txpool);
    CheckError(error);

    std::cout << "creating files" << std::endl;

    for(int i=0;i<1000;i++){
        std::strstream s;
        s << "file" << i << ".txt";
        error = svn_fs_make_file(root, s.str(), txpool);
        CheckError(error);
    }

    std::cout << "commit'ing" << std::endl;

    const char* conflict;
    error = svn_fs_commit_txn(&conflict, &youngest_rev, txn, txpool);
    CheckError(error);
    svn_pool_clear(txpool);
    svn_pool_destroy(txpool);

    std::cout << "ok" << std::endl;

    svn_pool_clear(pool);
    svn_pool_destroy(pool);

    return 0;
}

The above code takes a long time to complete and memory usage peeks at
about 600MB.
What am I doing wrong?
I'm using svn-win32-1.4.6

- Lars

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_subversion.tigris.org
For additional commands, e-mail: users-help_at_subversion.tigris.org
Received on 2008-01-21 13:55:03 CET

This is an archived mail posted to the Subversion Users mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.