markoX Posted October 17, 2022 Share Posted October 17, 2022 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? Quote Link to comment https://forums.phpfreaks.com/topic/315430-i-want-to-simulate-social-network-activity-how-to-approach-the-problem/ Share on other sites More sharing options...
gizmola Posted October 17, 2022 Share Posted October 17, 2022 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 Quote Link to comment https://forums.phpfreaks.com/topic/315430-i-want-to-simulate-social-network-activity-how-to-approach-the-problem/#findComment-1601716 Share on other sites More sharing options...
markoX Posted October 17, 2022 Author Share Posted October 17, 2022 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? Quote Link to comment https://forums.phpfreaks.com/topic/315430-i-want-to-simulate-social-network-activity-how-to-approach-the-problem/#findComment-1601721 Share on other sites More sharing options...
gizmola Posted October 18, 2022 Share Posted October 18, 2022 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. Quote Link to comment https://forums.phpfreaks.com/topic/315430-i-want-to-simulate-social-network-activity-how-to-approach-the-problem/#findComment-1601749 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.