{"action":"created","issue":{"url":"https://api.github.com/repos/ornicar/lila/issues/2248","repository_url":"https://api.github.com/repos/ornicar/lila","labels_url":"https://api.github.com/repos/ornicar/lila/issues/2248/labels{/name}","comments_url":"https://api.github.com/repos/ornicar/lila/issues/2248/comments","events_url":"https://api.github.com/repos/ornicar/lila/issues/2248/events","html_url":"https://github.com/ornicar/lila/issues/2248","id":176375895,"number":2248,"title":"RelationActor: Should this variable be a concurrent map?","user":{"login":"Happy0","id":1145180,"avatar_url":"https://avatars.githubusercontent.com/u/1145180?v=3","gravatar_id":"","url":"https://api.github.com/users/Happy0","html_url":"https://github.com/Happy0","followers_url":"https://api.github.com/users/Happy0/followers","following_url":"https://api.github.com/users/Happy0/following{/other_user}","gists_url":"https://api.github.com/users/Happy0/gists{/gist_id}","starred_url":"https://api.github.com/users/Happy0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Happy0/subscriptions","organizations_url":"https://api.github.com/users/Happy0/orgs","repos_url":"https://api.github.com/users/Happy0/repos","events_url":"https://api.github.com/users/Happy0/events{/privacy}","received_events_url":"https://api.github.com/users/Happy0/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ornicar/lila/labels/bug","name":"bug","color":"e11d21"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-09-12T13:31:05Z","updated_at":"2016-09-13T20:41:09Z","closed_at":null,"body":"I was dealing with concurrency a bit in another project and it lead me down the rabbit hole to the following question:\r\n\r\nShould this map be concurrent? : \r\n\r\nhttps://github.com/ornicar/lila/blob/master/modules/relation/src/main/RelationActor.scala#L23\r\n\r\nIt is only ever written to by the actor (which is fine). However, it can be read from in a different thread to the actor here (in the execution context of the future reading it):\r\n\r\nhttps://github.com/ornicar/lila/blob/master/modules/relation/src/main/RelationActor.scala#L79\r\n\r\nI don't know enough about the internals of Java concurrency to know what the consequence of this could be :P.\r\n\r\nNote: I think that the other data structure (`onlinePlayings`) type (`ExpireSetMemo`) is already thread safe.\r\n\r\nIf the answer is 'yes', what data structure would you typically use for this? Something in the lila.memo package?  (I can submit a PR)"},"comment":{"url":"https://api.github.com/repos/ornicar/lila/issues/comments/246816761","html_url":"https://github.com/ornicar/lila/issues/2248#issuecomment-246816761","issue_url":"https://api.github.com/repos/ornicar/lila/issues/2248","id":246816761,"user":{"login":"Happy0","id":1145180,"avatar_url":"https://avatars.githubusercontent.com/u/1145180?v=3","gravatar_id":"","url":"https://api.github.com/users/Happy0","html_url":"https://github.com/Happy0","followers_url":"https://api.github.com/users/Happy0/followers","following_url":"https://api.github.com/users/Happy0/following{/other_user}","gists_url":"https://api.github.com/users/Happy0/gists{/gist_id}","starred_url":"https://api.github.com/users/Happy0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Happy0/subscriptions","organizations_url":"https://api.github.com/users/Happy0/orgs","repos_url":"https://api.github.com/users/Happy0/repos","events_url":"https://api.github.com/users/Happy0/events{/privacy}","received_events_url":"https://api.github.com/users/Happy0/received_events","type":"User","site_admin":false},"created_at":"2016-09-13T20:41:09Z","updated_at":"2016-09-13T20:41:09Z","body":"I guess conceptually it could create issues if the thread has a 'stale' view of the data structure as a memory fence instruction hasn't told the CPU to update its cache from the other CPU's cache (the one that wrote the user join / leave to the data structure.) \r\n\r\nThis could mean that the thread might see a user as being offline who is in fact online. Usually locks / the 'volatile' keyword updates another reading CPUs view of the data structure I think (via its cache.) However, I don't know if this is an issue in practise (especially because there's like 15 seconds between each time users are informed of joins / leaves.)\r\n\r\nI'll probably move it inside the actor at some point for my own sanity one day :P. I'll do another feature / bug fix first or whatever though!"}}
{"actor":{"display_login":"Happy0"}}