Jump to content

I want to simulate social network activity. How to approach the problem?


Recommended Posts

I'm a PHP dev, and I have been doing that for 10 years. I want to challenge myself and simulate social network activity, for example, something simple: liking posts and following people. For this example let's take a case where I have 100 generated ("fake") users and 1 real user (me).

I was thinking about 2 possible approaches:

1st approach

I act on behalf of generated users. For example real user posts a picture:

- Event is dispatched

- code takes random 80 users and assigns them as followers

- code takes random 50 users and assign them as they like the picture

That is a pretty straightforward approach, where code takes actions based on events (pic posted, user registered) and assign fake users to certain actions. I could use queues and workers on the server to approach this.

2nd approach

Each fake user acts as a real user. So in my case it would be 100 users but each user programmatically acts as a real user. That would mean that I would need to have 1 worker for each fake user, and then trigger user on every event that happens, like: user registered, user posted a pic and so on.

My thoughts

For example event is "user registered" and that event is distributed:

1st approach: I assign X number of users to be followers
2nd approach: each fake user "decides" (it can be random decision true/false) to follow a user or not

2nd approach seems more natural and more user based vs 1st approach where I just manipulate with fake users and assign them actions. I know AI would be great for it, I'm opened for that suggestions also. RIght now I'm just trying to figure out how to approach the problem and what would be possible solutions.

What worries me is how do I make each fake user to react to events, that means each user needs to be ran as a new process?

You excluded a possibility initially, which is that you can select a random group of users from the existing population to be followers, rather than "assigning x".   So a new user could start out with 0 followers, or "all followers".  What you didn't describe is the process by which new users are created.  So I would probably have a number of command line process jobs.

  • Create new user job  (includes initialization of following)
  • Add new post job
  • Read feed
    • randomly like
      • within reasonable threshold
    • randomly unfollow
      • within reasonable threshold  (probably want this to be relatively low)
    • randomly reply
22 hours ago, markoX said:

Fake users are generated by a command, I just run the command and generate XYZ amount of users

What you described... But how to read feed? Should each fake user read feed on its own or how did you imagine it?

I would again just have a command line job that selects 1-N random users from the user base, and will access their feed programmatically, using the basic method I outlined in my prior reply.  If you wanted to up the level of sophistication, you might make this asynchronous using something like https://github.com/spatie/async to provide a more realistic simulation, as your artificial users can each be running through the read/like/reply processing simultaneously.  This type of simulation can create the type of race conditions that might happen in reality but won't appear during normal unit or regression testing.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.