RFC: Implementation of Stackable::merge() #79

Closed
olekukonko opened this Issue Mar 21, 2013 · 15 comments

Comments

Projects
None yet
3 participants
Contributor

olekukonko commented Mar 21, 2013

Introduction

From the #76 it shows that Stackable is a different data type. It would be nice for you to be able to merge multiple Stackable

Prove of Concept

    class Storage extends Stackable {

        function run() {
        }

        function merge() {
            $arg = func_get_args();
            foreach ( $arg as $v ) {
                if ($v instanceof Stackable) {
                    foreach ( $stackable as $k => $s ) {
                        $this[$k] = $s;
                    }
                }
            }
        }
    }

    $x = new Storage();
    foreach ( range(1, 10) as $element ) {
        $x[] = $element;
    }

    $y = new Storage();
    foreach ( range("A", "G") as $element ) {
        $y[$element] = $element;
    }

    $x->merge($y);

    var_dump($x);

Owner

krakjoe commented Mar 21, 2013

The same as #78 goes for this, I'd like some more opinions ...

Contributor

chibisuke commented Mar 21, 2013

In this case you really got the problem of what to do with locking.

I'd suggest to create a userland class library that can handle such things. That way we'd not clutter the pthreads code with things that can aswell be done in userland, and at the same time have the advantage of not having to write such things from scratch each time.

Maybe have this as a PEAR component?

@krakjoe krakjoe added a commit that referenced this issue Mar 21, 2013

@krakjoe krakjoe help to support decent solutions to #78 and #79, native count()
superior handling of anonymous members
0db6ec0
Owner

krakjoe commented Mar 27, 2013

In progress

krakjoe closed this Mar 27, 2013

Owner

krakjoe commented Mar 30, 2013

@olekukonko, @chibisuke, @bwoebi implemented ...

You can merge bundled objects, the lock is held on both objects throughout the copy of the object store.
You can also merge normal objects and arrays .... you can merge any collection in other words ...

However ...

I'm not really sure about the implementation, if you merge an array of pthreads objects you might use more memory than necessary (and increase refcounts unnecessarily) ... so the code looks unecessarily complex, there is a default case that could in theory handle everything, but I prefer to be precise where it is not too much work ... this has the side effect of not being able to copy resources in an out of pthreads objects, but I'm not so bothered, they will always be officially unsupported, if you are using resources then you are crazy !!

Anyway, test away ... let me know when we are happy with it such that I can write up phpdoc

Contributor

olekukonko commented Mar 30, 2013

Interesting .... use more memory than necessary how many percentage are we taking about ?? I would give it a try and get back to you .....

Where is the link to the latest snapshots http://pthreads.org/snapshots/5.4/ is showing Forbidden

Owner

krakjoe commented Mar 30, 2013

I haven't rolled a snapshot yet, pthreads.org corrupted itself the other day, for some reason I decided it would be a good idea to use a cms called Get Simple, first time I looked at the code when it went wrong ... it is a bit too simple and ended up deleting all my content, and somehow making empty backups so no change of recovery ... I had to use waybackmachine if you can believe it to restore the content !!

I will do one today at some point I am working on a couple of other things at the minute that require different vms ...

To be precise, retain more memory ... we have some kind of difficult to detect issue with reference counts that has become apparent, but I can't trace it down ... hopefully testing this feature can provide some insight into the differences of using calls to merge on arrays of stackables and calling it on the individual stackables ... not much time for testing today though ...

Interested to hear about anything you do find ...

Think it's flexible enough as a pattern ?? I was thinking that the second param ($overwrite) could be an array or boolean, if an array then could be an array of indexes to not overwrite, gives more precise control when dealing with large objects/arrays ??

Contributor

olekukonko commented Apr 6, 2013

Get Simple looks good but any reason why not just use wordpress would do a good Job updating information , introductions or likes on examples and tutorials , share , integration with social networks .. I think this would help us improve pthread popularity

Well done on the work so far .. can't wait to see the next snapshots

Owner

krakjoe commented Apr 6, 2013

I put it up in an hour months and months ago and haven't really done anything since, I didn't use wordpress because pthreads.org is on a single core celeron server with 2gb of ram, I don't want to be running mysql really ... also, as you might have guessed I included the word simple when looking for a cms ...

I like the idea of a community centered around these ideas to drive pthreads forward, but I do not have the time to organize or moderate such a thing, I am struggling to keep up as it is (you've been waiting days for snapshots I still haven't had the time to do yet, and likely won't today) ...

I haven't yet had the time to make $overwrite what I want it to be (array|boolean), once I have done that I will do a snapshot, couple of days after that once we've all tested another release is due ...

Contributor

olekukonko commented Apr 6, 2013

If it ca capacity issue .. then we can registrar a simple shared hosting with companies like http://www.bluehost.com/ or any affordable cloud providers ...I can look into that if you want ......

I askied for the snapshots again because http://pthreads.org/snapshots/5.4/ still shows Forbidden or am i getting the url wrong ?

Owner

krakjoe commented Apr 6, 2013

A shared host is an issue because that wont give me the access I need to deploy pthreads. I intend or intended to have some demos online that you could see running and for that I need access for rebuild/pecl, so I got a cheap dedi from ovh, it's £12 a month or something ...

I fixed the .htaccess so you can get indexes again, I'm not sure merge is in snapshots yet ... you might want to get yourself a unix vm for testing (anything will do) as you can test as soon as I commit, windows builds require me to fire up specific vms, and always have many runnning, sometimes profiling long operations for work and such ... pthreads vms are seperate, I cannot mix ...

Owner

krakjoe commented Apr 7, 2013

Snapshots done ... test what we have so far I'll come back to it later in the week ...

Contributor

olekukonko commented Apr 7, 2013

Good Idea ... I would try and create Unix environment for testing ..... have started my testing, looking good so far would update with any issue. Thanks.

Contributor

olekukonko commented Apr 8, 2013

Trying to install this in my new environment but failed ...

[root@localhost ~]# pecl install https://github.com/krakjoe/pthreads/archive/master.tar.gz
downloading master ...
Starting to download master (71,559 bytes)
.................done: 71,559 bytes
ERROR: file /tmp/pear/install/tmpReS3rq/pthreads-0.0.43/examples/CallAnyFunction.php does not exist

Any tips ??

Owner

krakjoe commented Apr 8, 2013

git clone https://github.com/krakjoe/pthreads
cd pthreads
phpize
./configure --with-php-config=/path/to/php-config
make
make install

The pecl binary is only meant for installation from the pecl cdn, I believe you can use it to build a source package but at any time the package.xml in the git repo is only bang up to date on release dates.

Contributor

olekukonko commented Apr 12, 2013

Thanks for the info ....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment